A Ruby gem that loads environment variables from .env files into ENV, primarily for development.
Dotenv is a Ruby library that loads environment variables from .env files into the ENV hash, simplifying configuration management. It follows the twelve-factor app principle by extracting configuration like database credentials or API keys from code into environment variables. This is particularly useful in development and testing where manually setting environment variables is impractical.
Ruby developers, especially those using Rails, Sinatra, or Rake, who need a consistent way to manage environment-specific configuration across different deployment stages. It's also aimed at teams practicing twelve-factor app methodologies.
Developers choose dotenv for its simplicity, framework integration (like automatic loading in Rails), and features like environment-specific file support and autorestore for tests. It avoids overwriting existing ENV variables by default, respecting deployment environment settings while providing local configuration flexibility.
A Ruby gem to load environment variables from .env.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Automatically loads environment variables when Rails boots with customizable file precedence (e.g., .env.development.local overrides .env), reducing boilerplate code.
Includes autorestore functionality to automatically reset ENV after each test in Rails, preventing state leakage in test suites using ActiveSupport::TestCase or Rspec.
Allows referencing other variables in .env files using ${VAR} syntax, enabling dynamic configuration like DATABASE_URL="postgres://${USER}@localhost/my_database".
Provides Dotenv.require_keys to raise errors during initialization if essential configuration keys are missing, avoiding runtime failures in production.
Includes a dotenv executable for loading variables before running scripts and can generate .env.template files for documentation and onboarding.
By default, dotenv won't overwrite existing ENV variables, which can lead to confusion when local .env files are ignored unless overwrite: true is explicitly set.
Handling multi-line values requires double quotes and awareness of the DOTENV_LINEBREAK_MODE for legacy support, adding setup complexity compared to simpler alternatives.
As a Ruby gem, it's not usable in projects with other languages, limiting its utility in mixed-technology stacks where consistent configuration management is needed.
Support for multiple environment-specific files (e.g., .env.development.local, .env.local) can lead to clutter and confusion if not carefully managed, especially in larger teams.