Skip to main content

Environment Variables | GoRails

General • Asked by Chris Oliver

Very clear about how the export command and subsequently the .bash_profile file work. We're currently taking advantage of this strategy by telling Puppet to deploy our keys into our servers and setting them in ENV variables instead of having them in our repos. Thanks.


So awesome. It's great to see this kind of foundational content before delving into Rails. And it's nice to see the mentions of zsh, rbenv, irb, vim, etc so that those of us who are new to things can pick up on some bonus material outside of the main env topic.


Nice. Thanks!


Thank goodness, finally a video that explains this perfectly. Love it. Really like the part where you took time to explain how the environment variable will be "temporary", "semi temporary", and then "permanent" because .bash_profile is loaded when the terminal runs. It was also good to see the larger picture that this is very useful to store API keys locally


That was a really helpful guide, thanks for posting it. Keep up the good work!


A really really nice explanation of env vars. I did not find more simpler and more clearer explanation to the thing that always sorta bugged me since it had too much "magic" in it.
Thanks a ton Chris.


.bash_profile vs. .bashrc, and why MacOS X Terminal.app is an exception, for the possibly confused: http://www.joshstaiger.org/...


Nice! I used this to create shortcuts for myself. For example, I can type 'dev' into my terminal, and it changes directory to my Development folder.


I have a question regarding ENV variables.

Suppose I have just a single Rails appon my Development environment. Then in this case I could use ENV vars to save my db credentials, so I could do something like this on my bashrc file:

export DB_USERNAME="my-username"
export DB_PASSWORD="my-password"
export DATABASE="railsapp_development"

This seems pretty straight forward but what there are more than one project on the development environment? I guess the username and password are same, but the database name changes on each project because projects don't usually share the same database, right?

How to use a different database name for each project in this case then?

Check out https://github.com/rbenv/rb...

This lets you write a .rbenv-vars file in your rails app directory and set environment variables separately outside of your Rails app.

I'm using this for the new Rails hosting service I'm working on and it works wonderfully for separating environment variables out for each app.

I notice it says rbenv. I'm having rvm, is there any similar in this case?


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.