ENV variables in Rails 7.x

This might be silly but I need help in finding where my ENV file is. I am unable to view my ENV file.

When I started my rails app, some of the values were ENV[“var_name”], eg: ENV[" DATABASE_PASSWORD"] so I assumed those environment variables must be stored somewhere. but it is nowhere to be found.

When it comes to the “Figaro” gem we store it in config/application.yml. Another way is storing them in other YML files and loading them in the “config” folder. but there is no code added for it. since it is newly created, no code was added to the Rails app.

I also checked my Gemfile and Gemlock files. there was no “Dotenv” or “Figaro” present. Does Rails provide this ENV feature thing in-built?

I might be missing something or might not be aware of something. Enlighten me on how to view this file and update the ENV variables. Thanks, folks.

p.s: I use a Windows machine.

If you are using rbenv, you might have a .rbenv-var files with that.

If not, then ruby by default pulls the exported variables from your shell. Take a look at ~/.bashrc or ~/.zshrc

1 Like

ENV gets its values from the UNIX environment, which you can see from the command line (where you type rails s or rake):


In production, this is a decent place to store stuff like database credentials. For local development, it’s not a very good place, so you can use dotenv to allow them to be kept in a file. You want to use the dotenv-rails variant, which will set itself automatically.

Once you have that, create two files: .env.development and .env.test, and place your dev and test values, respectively, in there:

# .env.development

# .env.test

If those files have secrets you don’t want in verison control, don’t check them in or put safe-to-checkin-to-verdsion control stuff in those files, check those in, and put not-safe-to-checkin into .env.development.local and .env.test.local