dotenv is a Ruby gem that loads environment variables from a `.env` file into the application's ENV hash during development.
The tool addresses the practical challenge of managing environment-specific configuration without hardcoding secrets or deployment-dependent values into source code. Following twelve-factor app principles, dotenv reads a `.env` file in your project root and populates environment variables that your application can access. This approach avoids the friction of manually setting environment variables on each development machine or CI server, while keeping sensitive data and environment-specific settings out of version control.
Rails applications load dotenv automatically on boot with no additional setup required. For Sinatra or other Ruby applications, you call the load method early in your bootstrap process. The tool supports loading multiple files in priority order, with the first value set for any variable winning out, and existing environment variables are preserved unless you explicitly enable overwriting. A command-line executable lets you prefix application launches with dotenv to ensure variables are loaded before your app starts. The tool also provides an autorestore feature in test environments that automatically resets ENV after each test, preventing state leakage between tests without requiring manual cleanup.
The project maintains steady, focused development activity with regular updates addressing edge cases and test compatibility. Maintenance includes ongoing attention to test infrastructure and ensuring compatibility with evolving Ruby and Rails versions. The tool receives periodic refinements to its core loading logic and configuration handling.