How to set Rails environment?

May 26, 2014 37.4k views
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.
6 Answers
You need to either run
export RAILS_ENV=production
which will last until your exit your shell (log out), or prepend RAILS_ENV=production to the command you're trying to run, e.g.:
RAILS_ENV=production rake about
OK, thanks! I managed to switch to production mode somehow but don't remember exactly how I did it.

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

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

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.

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.

Have another answer? Share your knowledge.

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