Just a quick question to which I couldn't find an answer on stackoverflow.
If it is easy to have environment variable for staging and production (on heroku for example), how can I set environment variable for my localhost (development environment)? (I am on a mac)
As of today I hardcode my api credential for development environment and I don't feel comfortable with that.
Thanks !
Environment variables are best placed in your
.bash_profile
file which lives in your home directory on the Mac:/Users/you/.bash_profile
. Open that file and add something like this to the end of it:or
export is a shell command that sets environment variables. Your
.bash_profile
is a bash script that runs every time you open a new shell session (open a terminal window) and therefore yourexport
commands will run and set the env vars.Then they will be available in the
ENV
constant when you're in Ruby.Edit
/Users/your_user_name/.bash_profile
and add there:Use
dotenv
is intended to be used in development:Add your application configuration to your
.env
file in the root of your project.You may also add export in front of each line so you can source the file in bash. in
.bashrc
Then access in rails app
ENV['S3_BUCKET']