.env · generator · Ruby on Rails

Ruby on Rails .env Generator

Rails ships with encrypted credentials, but dotenv-rails is still the path of least resistance for local dev. This generator produces a .env with database, Redis, Sidekiq, and secret keys.

.env for Ruby on Rails · 5 keys
Customize →
RAILS_ENV=development
RAILS_MASTER_KEY=swsKoiGRkReYswS8BC3AxMgdysSm3-8iQuMGX-tWZPprWeRy
DATABASE_URL=postgres://user:password@localhost:5432/mydb
REDIS_URL=redis://localhost:6379/0
SECRET_KEY_BASE=TYo5kdvwVTJzc-hgwN0ANv3UKDLNdraM0CIL7RMVESxJFgH5

Secrets regenerate on every page load. Want to combine stacks (e.g., Next.js + Stripe + Supabase)? Use the full generator.

How to use this .env in Ruby on Rails

  1. 1.Add gem 'dotenv-rails' to the :development, :test group in Gemfile.
  2. 2.Run bundle install.
  3. 3.Save the output as .env in the project root.
  4. 4.Access with ENV['KEY'] anywhere in the app.
  5. 5.For production, prefer Rails encrypted credentials (rails credentials:edit).

Gotchas

  • dotenv-rails loads AFTER boot — use config/application.rb for config-time values via credentials instead.
  • Don't commit config/master.key. It's auto-added to .gitignore on new apps.
  • RAILS_LOG_TO_STDOUT=1 is needed for Heroku/Fly to see logs.

Common keys explained

RAILS_ENV

Environment — development | test | production.

DATABASE_URL

Postgres connection string (Rails 7 reads this natively).

RAILS_MASTER_KEY

Key that decrypts config/credentials.yml.enc.

REDIS_URL

Redis used by Sidekiq + Action Cable.

SECRET_KEY_BASE

Fallback signing key; typically set via credentials.

Related tools

Other stacks