Sorry this page looks weird. It was automatically migrated from my old blog, which had a different layout and different CSS.

Avoid Typing RAILS_ENV All The Time

I often log into my staging or production servers to run a Rake task or fire up the Rails console. I got fed up long ago with specifying the environment in every command. For example:

$ rake --trace db:migrate:redo RAILS_ENV=production
$ script/console production
$ rake ts:in RAILS_ENV=production

It just occurred to me to set the environment variable in, er, the environment (~/.bashrc):

export RAILS_ENV=production

And now I can log in and type simply what I want to type:

$ rake --trace db:migrate:redo
$ script/console
$ rake ts:in

I am so embarrassed that I didn’t think of this three years ago.

Andrew Stewart • 10 April 2009 • RailsDeploymentRuby
You can reach me by email or on Twitter.