Question

How to set Rails environment?

  • Posted May 26, 2014

I have a 1-click installation of Ruby on Rails 4, NginX, and Ubuntu running on my droplet.

Unfortunately, I haven’t found a way to create my production database from my schema.rb file yet.

I think this is due to the fact that my Rails environment is still set to “development”. When I type “rake about” I get this:

Application root /home/rails Environment development Database adapter sqlite3

I would like to set my app to production mode, though. I would also like to use MySQL instead of SQLite.

How can this be done?

Typing “RAILS_ENV=production” seems to have no effect whatsoever.

Thanks for any help.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Yes, this is what I ended up doing (5 years after posting the initial question) and it seems to work.

More on rbenv-vars can be found here.

I personally use a .rbenv-vars file in the root of each Rails project. There you can set all your project specific env vars and they’re going to be automatically loaded by rbenv.

Good point. Have you found a solution to this yet?

This is pointless, how do we set the environment PERMANENTLY?

OK, thanks! I managed to switch to production mode somehow but don’t remember exactly how I did it.

You need to either run <pre>export RAILS_ENV=production</pre> which will last until your exit your shell (log out), or prepend <code>RAILS_ENV=production </code> to the command you’re trying to run, e.g.: <pre>RAILS_ENV=production rake about</pre>