[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-7686":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":21,"hasPages":21,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":25,"readmeContent":26,"aiSummary":27,"trendingCount":16,"starSnapshotCount":16,"syncStatus":28,"lastSyncTime":29,"discoverSource":30},7686,"dotenv","bkeepers\u002Fdotenv","bkeepers","A Ruby gem to load environment variables from `.env`. ","",null,"Ruby",6760,514,68,12,0,1,17,66.34,"MIT License",false,"main",[5,24],"ruby","2026-06-12 04:00:35","# dotenv [![Gem Version](https:\u002F\u002Fbadge.fury.io\u002Frb\u002Fdotenv.svg)](https:\u002F\u002Fbadge.fury.io\u002Frb\u002Fdotenv)\n\nShim to load environment variables from `.env` into `ENV` in *development*.\n\nStoring [configuration in the environment](http:\u002F\u002F12factor.net\u002Fconfig) is one of the tenets of a [twelve-factor app](http:\u002F\u002F12factor.net). Anything that is likely to change between deployment environments–such as resource handles for databases or credentials for external services–should be extracted from the code into environment variables.\n\nBut it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. dotenv loads variables from a `.env` file into `ENV` when the environment is bootstrapped.\n\n## Installation\n\nAdd this line to the top of your application's Gemfile and run `bundle install`:\n\n```ruby\ngem 'dotenv', groups: [:development, :test]\n```\n\n## Usage\n\nAdd your application configuration to your `.env` file in the root of your project:\n\n```shell\nS3_BUCKET=YOURS3BUCKET\nSECRET_KEY=YOURSECRETKEYGOESHERE\n```\n\nWhenever your application loads, these variables will be available in `ENV`:\n\n```ruby\nconfig.fog_directory = ENV['S3_BUCKET']\n```\n\nSee the [API Docs](https:\u002F\u002Frubydoc.info\u002Fgithub\u002Fbkeepers\u002Fdotenv\u002Fmain) for more.\n\n### Rails\n\nDotenv will automatically load when your Rails app boots. See [Customizing Rails](#customizing-rails) to change which files are loaded and when.\n\n### Sinatra \u002F Ruby\n\nLoad Dotenv as early as possible in your application bootstrap process:\n\n```ruby\nrequire 'dotenv\u002Fload'\n\n# or\nrequire 'dotenv'\nDotenv.load\n```\n\nBy default, `load` will look for a file called `.env` in the current working directory.\nPass in multiple files and they will be loaded in order.\nThe first value set for a variable will win.\nExisting environment variables will not be overwritten unless you set `overwrite: true`.\n\n```ruby\nrequire 'dotenv'\nDotenv.load('file1.env', 'file2.env')\n```\n\n### Autorestore in tests\n\nSince 3.0, dotenv in a Rails app will automatically restore `ENV` after each test. This means you can modify `ENV` in your tests without fear of leaking state to other tests. It works with both `ActiveSupport::TestCase` and `Rspec`.\n\nTo disable this behavior, set `config.dotenv.autorestore = false` in `config\u002Fapplication.rb` or `config\u002Fenvironments\u002Ftest.rb`. It is disabled by default if your app uses [climate_control](https:\u002F\u002Fgithub.com\u002Fthoughtbot\u002Fclimate_control) or [ice_age](https:\u002F\u002Fgithub.com\u002Fdpep\u002Fice_age_rb).\n\nTo use this behavior outside of a Rails app, just `require \"dotenv\u002Fautorestore\"` in your test suite.\n\nSee [`Dotenv.save`](https:\u002F\u002Frubydoc.info\u002Fgithub\u002Fbkeepers\u002Fdotenv\u002Fmain\u002FDotenv:save), [Dotenv.restore](https:\u002F\u002Frubydoc.info\u002Fgithub\u002Fbkeepers\u002Fdotenv\u002Fmain\u002FDotenv:restore), and [`Dotenv.modify(hash) { ... }`](https:\u002F\u002Frubydoc.info\u002Fgithub\u002Fbkeepers\u002Fdotenv\u002Fmain\u002FDotenv:modify) for manual usage.\n\n### Rake\n\nTo ensure `.env` is loaded in rake, load the tasks:\n\n```ruby\nrequire 'dotenv\u002Ftasks'\n\ntask mytask: :dotenv do\n  # things that require .env\nend\n```\n\n### CLI\n\nYou can use the `dotenv` executable load `.env` before launching your application:\n\n```console\n$ dotenv .\u002Fscript.rb\n```\n\nThe `dotenv` executable also accepts the flag `-f`. Its value should be a comma-separated list of configuration files, in the order of the most important to the least important. All of the files must exist. There _must_ be a space between the flag and its value.\n\n```console\n$ dotenv -f \".env.local,.env\" .\u002Fscript.rb\n```\n\nThe `dotenv` executable can optionally ignore missing files with the `-i` or `--ignore` flag. For example, if the `.env.local` file does not exist, the following will ignore the missing file and only load the `.env` file.\n\n```console\n$ dotenv -i -f \".env.local,.env\" .\u002Fscript.rb\n```\n\n### Load Order\n\nIf you use gems that require environment variables to be set before they are loaded, then list `dotenv` in the `Gemfile` before those other gems and require `dotenv\u002Fload`.\n\n```ruby\ngem 'dotenv', require: 'dotenv\u002Fload'\ngem 'gem-that-requires-env-variables'\n```\n\n### Customizing Rails\n\nDotenv will load the following files depending on `RAILS_ENV`, with the first file having the highest precedence, and `.env` having the lowest precedence:\n\n\u003Ctable>\n  \u003Cthead>\n    \u003Ctr>\n      \u003Cth>Priority\u003C\u002Fth>\n      \u003Cth colspan=\"3\">Environment\u003C\u002Fth>\n      \u003Cth>\u003Ccode>.gitignore\u003C\u002Fcode>it?\u003C\u002Fth>\n      \u003Cth>Notes\u003C\u002Fth>\n    \u003C\u002Ftr>\n    \u003Ctr>\n      \u003Cth>\u003C\u002Fth>\n      \u003Cth>development\u003C\u002Fth>\n      \u003Cth>test\u003C\u002Fth>\n      \u003Cth>production\u003C\u002Fth>\n      \u003Cth>\u003C\u002Fth>\n      \u003Cth>\u003C\u002Fth>\n    \u003C\u002Ftr>\n  \u003C\u002Fthead>\n  \u003Ctr>\n    \u003Ctd>highest\u003C\u002Ftd>\n    \u003Ctd>\u003Ccode>.env.development.local\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003Ctd>\u003Ccode>.env.test.local\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003Ctd>\u003Ccode>.env.production.local\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003Ctd>Yes\u003C\u002Ftd>\n    \u003Ctd>Environment-specific local overrides\u003C\u002Ftd>\n  \u003C\u002Ftr>\n  \u003Ctr>\n    \u003Ctd>2nd\u003C\u002Ftd>\n    \u003Ctd>\u003Ccode>.env.local\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003Ctd>\u003Cstrong>N\u002FA\u003C\u002Fstrong>\u003C\u002Ftd>\n    \u003Ctd>\u003Ccode>.env.local\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003Ctd>Yes\u003C\u002Ftd>\n    \u003Ctd>Local overrides\u003C\u002Ftd>\n  \u003C\u002Ftr>\n  \u003Ctr>\n    \u003Ctd>3rd\u003C\u002Ftd>\n    \u003Ctd>\u003Ccode>.env.development\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003Ctd>\u003Ccode>.env.test\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003Ctd>\u003Ccode>.env.production\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003Ctd>No\u003C\u002Ftd>\n    \u003Ctd>Shared environment-specific variables\u003C\u002Ftd>\n  \u003C\u002Ftr>\n  \u003Ctr>\n    \u003Ctd>last\u003C\u002Ftd>\n    \u003Ctd>\u003Ccode>.env\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003Ctd>\u003Ccode>.env\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003Ctd>\u003Ccode>.env\u003C\u002Fcode>\u003C\u002Ftd>\n    \u003Ctd>\u003Ca href=\"#should-i-commit-my-env-file\">Maybe\u003C\u002Fa>\u003C\u002Ftd>\n    \u003Ctd>Shared for all environments\u003C\u002Ftd>\n  \u003C\u002Ftr>\n\u003C\u002Ftable>\n\n\nThese files are loaded during the `before_configuration` callback, which is fired when the `Application` constant is defined in `config\u002Fapplication.rb` with `class Application \u003C Rails::Application`. If you need it to be initialized sooner, or need to customize the loading process, you can do so at the top of `application.rb`\n\n```ruby\n# config\u002Fapplication.rb\nBundler.require(*Rails.groups)\n\n# Load .env.local in test\nDotenv::Rails.files.unshift(\".env.local\") if ENV[\"RAILS_ENV\"] == \"test\"\n\nmodule YourApp\n  class Application \u003C Rails::Application\n    # ...\n  end\nend\n```\n\nAvailable options:\n\n* `Dotenv::Rails.files` - list of files to be loaded, in order of precedence.\n* `Dotenv::Rails.overwrite` - Overwrite existing `ENV` variables with contents of `.env*` files\n* `Dotenv::Rails.logger` - The logger to use for dotenv's logging. Defaults to `Rails.logger`\n* `Dotenv::Rails.autorestore` - Enable or disable [autorestore](#autorestore-in-tests)\n\n### Multi-line values\n\nMulti-line values with line breaks must be surrounded with double quotes.\n\n```shell\nPRIVATE_KEY=\"-----BEGIN RSA PRIVATE KEY-----\n...\nHkVN9...\n...\n-----END DSA PRIVATE KEY-----\"\n```\n\nPrior to 3.0, dotenv would replace `\\n` in quoted strings with a newline, but that behavior is deprecated. To use the old behavior, set `DOTENV_LINEBREAK_MODE=legacy` before any variables that include `\\n`:\n\n```shell\nDOTENV_LINEBREAK_MODE=legacy\nPRIVATE_KEY=\"-----BEGIN RSA PRIVATE KEY-----\\nHkVN9...\\n-----END DSA PRIVATE KEY-----\\n\"\n```\n\n### Command Substitution\n\nYou need to add the output of a command in one of your variables? Simply add it with `$(your_command)`:\n\n```shell\nDATABASE_URL=\"postgres:\u002F\u002F$(whoami)@localhost\u002Fmy_database\"\n```\n\n### Variable Substitution\n\nYou need to add the value of another variable in one of your variables? You can reference the variable with `${VAR}` or often just `$VAR` in unquoted or double-quoted values.\n\n```shell\nDATABASE_URL=\"postgres:\u002F\u002F${USER}@localhost\u002Fmy_database\"\n```\n\nIf a value contains a `$` and it is not intended to be a variable, wrap it in single quotes.\n\n```shell\nPASSWORD='pas$word'\n```\n\n### Comments\n\nComments may be added to your file as such:\n\n```shell\n# This is a comment\nSECRET_KEY=YOURSECRETKEYGOESHERE # comment\nSECRET_HASH=\"something-with-a-#-hash\"\n```\n\n### Exports\n\nFor compatability, you may also add `export` in front of each line so you can `source` the file in bash:\n\n```shell\nexport S3_BUCKET=YOURS3BUCKET\nexport SECRET_KEY=YOURSECRETKEYGOESHERE\n```\n\n### Required Keys\n\nIf a particular configuration value is required but not set, it's appropriate to raise an error.\n\nTo require configuration keys:\n\n```ruby\n# config\u002Finitializers\u002Fdotenv.rb\n\nDotenv.require_keys(\"SERVICE_APP_ID\", \"SERVICE_KEY\", \"SERVICE_SECRET\")\n```\n\nIf any of the configuration keys above are not set, your application will raise an error during initialization. This method is preferred because it prevents runtime errors in a production application due to improper configuration.\n\n### Parsing\n\nTo parse a list of env files for programmatic inspection without modifying the ENV:\n\n```ruby\nDotenv.parse(\".env.local\", \".env\")\n# => {'S3_BUCKET' => 'YOURS3BUCKET', 'SECRET_KEY' => 'YOURSECRETKEYGOESHERE', ...}\n```\n\nThis method returns a hash of the ENV var name\u002Fvalue pairs.\n\n### Templates\n\nYou can use the `-t` or `--template` flag on the dotenv cli to create a template of your `.env` file.\n\n```console\n$ dotenv -t .env\n```\nA template will be created in your working directory named `{FILENAME}.template`. So in the above example, it would create a `.env.template` file.\n\nThe template will contain all the environment variables in your `.env` file but with their values set to the variable names.\n\n```shell\n# .env\nS3_BUCKET=YOURS3BUCKET\nSECRET_KEY=YOURSECRETKEYGOESHERE\n```\n\nWould become\n\n```shell\n# .env.template\nS3_BUCKET=S3_BUCKET\nSECRET_KEY=SECRET_KEY\n```\n\n## Frequently Answered Questions\n\n### Can I use dotenv in production?\n\ndotenv was originally created to load configuration variables into `ENV` in *development*. There are typically better ways to manage configuration in production environments - such as `\u002Fetc\u002Fenvironment` managed by [Puppet](https:\u002F\u002Fgithub.com\u002Fpuppetlabs\u002Fpuppet) or [Chef](https:\u002F\u002Fgithub.com\u002Fchef\u002Fchef), `heroku config`, etc.\n\nHowever, some find dotenv to be a convenient way to configure Rails applications in staging and production environments, and you can do that by defining environment-specific files like `.env.production` or `.env.test`.\n\nIf you use this gem to handle env vars for multiple Rails environments (development, test, production, etc.), please note that env vars that are general to all environments should be stored in `.env`. Then, environment specific env vars should be stored in `.env.\u003Cthat environment's name>`.\n\n### Should I commit my .env file?\n\nCredentials should only be accessible on the machines that need access to them. Never commit sensitive information to a repository that is not needed by every development machine and server.\n\nPersonally, I prefer to commit the `.env` file with development-only settings. This makes it easy for other developers to get started on the project without compromising credentials for other environments. If you follow this advice, make sure that all the credentials for your development environment are different from your other deployments and that the development credentials do not have access to any confidential data.\n\n### Why is it not overwriting existing `ENV` variables?\n\nBy default, it **won't** overwrite existing environment variables as dotenv assumes the deployment environment has more knowledge about configuration than the application does. To overwrite existing environment variables you can use `Dotenv.load files, overwrite: true`.\n\nTo warn when a value was not overwritten (e.g. to make users aware of this gotcha),\nuse `Dotenv.load files, overwrite: :warn`.\n\nYou can also use the `-o` or `--overwrite` flag on the dotenv cli to overwrite existing `ENV` variables.\n\n```console\n$ dotenv -o -f \".env.local,.env\"\n```\n\n## Contributing\n\nIf you want a better idea of how dotenv works, check out the [Ruby Rogues Code Reading of dotenv](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=lKmY_0uY86s).\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Added some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","dotenv 是一个 Ruby 宝石，用于从 `.env` 文件中加载环境变量到 `ENV` 中。其核心功能是在开发环境中将配置信息从代码中提取出来并存储在环境变量里，遵循十二要素应用的配置原则。它支持在 Rails、Sinatra 或其他 Ruby 应用中自动或手动加载环境变量，并且在测试过程中能够自动恢复 `ENV` 状态以避免状态泄露。适合于需要在不同部署环境下灵活管理配置参数的 Ruby 项目，特别是在开发和持续集成环境中，通过 `.env` 文件简化环境变量设置过程。",2,"2026-06-11 03:13:46","top_language"]