Every Ruby service starts with three environment variables and ends with a 400-line config/initializers/monkey_patch.rb. Somewhere between the first deploy and the third on-call rotation, configuration turns into an archaeology project: half the truth lives in config/settings.yml, half in Kubernetes secrets, and the remaining half in a ENV.fetch call buried inside a background worker that only runs at 3am.
The three libraries below solve that problem from three different angles. They are also frequently confused with each other, because all of them promise “configuration you can reason about” and none of them ship a UI that makes the difference obvious.
Quick verdict: use dry-configurable if you are writing a gem or a service object and want a typed, inheritable config schema. Use Anyway Config if you run a Rails app that needs YAML, credentials, and ENV merged with a clear precedence order. Use the Config gem if you want Settings.foo access across a Rails codebase with almost no ceremony and you are comfortable with global state.
The Three Contenders at a Glance
| Criterion | dry-configurable | Anyway Config | Config gem |
|---|---|---|---|
| Latest release | 1.4.0 (May 2026) | 2.9.1 (Oct 2026) | 5.6.1 (Jul 2025) |
| GitHub stars | 427 | 924 | 2,172 |
| Last commit | Nov 2026 | Oct 2026 | Jul 2026 |
| Total gem downloads | 201M | 37.9M | 60.7M |
| Layered YAML files | No | Yes (per-environment, ERB) | Yes (per-environment, ERB) |
Automatic ENV overrides | No | Yes (PREFIX_KEY, __ for nesting) | Yes (use_env = true) |
| Type coercion | Yes (via dry-types constructors) | Yes (built-in, plus _INT/_BOOL suffixes) | Limited (YAML types only) |
| Required-key validation | Manual | Yes (required :api_key) | No |
| Rails credentials support | No | Yes (credentials and secrets loaders) | No (you wire it yourself) |
| Reload at runtime | No (frozen config) | Yes (reload!) | Yes (Settings.reload!) |
| Typical user | Gem authors, POROs | Rails apps, multi-source configs | Classic Rails monoliths |
The star counts are not close, and that is the first trap: the Config gem is the most popular of the three, but also the least strict. Popularity here reflects how long a library has been around, not how well it handles a 20-service deployment.
Decision Matrix: Pick in Ten Seconds
| Your situation | Recommended | Why |
|---|---|---|
| You publish a gem and need defaults users can override | dry-configurable | Inheritable schema, no global state, no Rails dependency |
Monolith with config/settings.yml and a Settings.* habit | Config gem | Zero-friction migration, Settings.reload! for ops |
App with credentials, YAML, and ENV fighting each other | Anyway Config | Explicit precedence: YAML < secrets < credentials < ENV |
Twelve-factor app where ENV is the only source of truth | Anyway Config or dry-configurable | Both coerce strings into real types; Config gem needs use_env |
| Library code that must not read global constants | dry-configurable | Config lives on the class, not in a global namespace |
| You need runtime validation at boot | Anyway Config | required raises Anyway::Config::ValidationError early |
dry-configurable — A Schema for Gems and Service Objects
dry-configurable is the smallest of the three. It bolts a settings DSL onto any class, keeps the config object namespaced to that class, and freezes it when the class is done loading. That design makes it the default choice for gem authors: no global constant, no Rails assumption, no YAML loader to fight.
| |
| |
Two details matter in practice. First, settings are inherited by subclasses, so a Billing::SandboxClient < Billing::Client can override endpoint without duplicating the schema. Second, the config object is frozen after the class body finishes evaluating — writes must go through configure, which is exactly the guardrail that prevents a random initializer from mutating config at request time.
Where dry-configurable stops is layering. There is no YAML loader, no ENV prefix convention, no per-environment file. The default: -> { ENV.fetch(...) } lambda above is the entire environment story, and it only works because the lambda is evaluated lazily. If you need staging.yml to override production.yml, you are writing that loader yourself.
For coercion, pair it with dry-types:
| |
Now BILLING_TIMEOUT=30 converted to an integer by your own bootstrap code will be rejected if someone sets it to "thirty", instead of silently comparing a string to a number three layers deeper.
Anyway Config — Layered YAML, Credentials, and ENV in One Object
Anyway Config exists because Rails apps accumulate configuration sources faster than they accumulate tests. Its documented precedence order, from lowest to highest priority, is: YAML file, Rails secrets (pre-7.1), Rails credentials, then ENV. Explicit arguments passed to the constructor win over everything.
| |
| |
The YAML file is namespaced by Rails environment, and config/payments.yml with a production: key is all it takes:
| |
Environment variables use the config name as a prefix, and a double underscore for nesting: PAYMENTS_API_KEY, PAYMENTS_TIMEOUT=2.5, PAYMENTS_SMTP__PORT=587. Arrays are parsed from comma-separated values, so PAYMENTS_ALLOWED_IPS=10.0.0.1,10.0.0.2 becomes a real array. Booleans declared with a false default get a predicate method for free:
| |
The required :api_key line is the feature that justifies the dependency for most teams. It fails at boot, in the environment that is missing the key, with a message naming the attribute — not at 2am inside a payment retry. You can suppress that check in CI with ANYWAY_SUPPRESS_VALIDATIONS, which is the escape hatch you want when your test suite has no secrets.
One caveat worth knowing before you commit: config classes placed in app/configs are autoloaded and therefore unusable during initialization. If you need config inside config/initializers/*.rb, put the classes in config/configs instead, where Anyway Config’s custom autoloader picks them up early.
Config Gem — The Rails-Native Settings.* Approach
The Config gem is the oldest and least opinionated option. After rails g config:install you get a settings tree and a global Settings constant:
| |
| |
| |
The load order is config/settings.yml, then config/settings/#{environment}.yml, then config/environments/#{environment}.yml, with settings.local.yml files layered on top for developer-specific overrides. Those local files are gitignored by the generator, which solves the “who committed their laptop path” problem permanently.
ENV support is opt-in and slightly awkward:
| |
With that in place, SETTINGS__API_URL overrides the file value, and SETTINGS__SMTP__PORT reaches two levels deep. Note the defaults: env_prefix defaults to the constant name and env_separator defaults to a dot, which bash will not let you export. Set the separator explicitly or you will spend an afternoon debugging variables that “look right”.
What the Config gem does not give you is a schema. Any key can be any type, nothing is required, and a typo in Settings.timout returns nil instead of raising. In a small monolith that is fine. In a service with 40 settings, it is how outages get shipped.
Head-to-Head on Real Workloads
Boot-time failure detection. Anyway Config wins outright: required plus constructor-time coercion means a missing key stops the process before it accepts traffic. dry-configurable can do the same if you add dry-types constructors and call config in an initializer — but you have to remember to do it. The Config gem will happily boot with nil.
Test isolation. dry-configurable is the cleanest, because config lives on the class and can be duplicated per test. Anyway Config allows MyConfig.new(overrides) and a clear/reload! pair, which is workable. The global Settings constant in the Config gem is the usual source of order-dependent test failures; Settings.reload! in a before hook is mandatory.
Multiple processes. Puma workers, Sidekiq processes, and Rake tasks all read the same files. File-based config reloads differently in each: Puma needs a phased restart, Sidekiq needs a signal, and a Rake task just reads whatever exists at invocation. Anyway Config’s reload! is the only one of the three that gives you a per-instance refresh without a restart, but you still have to trigger it from somewhere.
Precedence clarity. This is the criterion teams underestimate. Anyway Config documents its order and enforces it. The Config gem’s order is documented but easy to break with add_source!. dry-configurable has no order because it has no sources — which is a feature for a gem, and a gap for an app.
Deployment Patterns: Docker, Kubernetes, and Boot Order
For a containerized Rails app, the practical pattern is: bake non-secret defaults into the image, inject secrets from the orchestrator, and never mount a writable config directory.
| |
Two things about that healthcheck. First, it validates configuration, not just liveness — a container that cannot read its payment key should never report healthy. Second, mount config files read-only. Configuration that can be edited in place turns into configuration that drifts between replicas.
For Kubernetes, keep the YAML in a ConfigMap and the secrets in a Secret, then let the library’s precedence do the work:
| |
If you run all three replicas from the same ConfigMap, Settings.reload! after a ConfigMap update is not automatic — Kubernetes does not restart pods for you. Either roll the deployment or accept that config changes need a rollout. Pretending otherwise is how you get three pods running three different timeouts.
Pitfalls That Bite in Production
- Coercion happens once.
ENVvalues are strings. Anyway Config and dry-configurable convert them; the Config gem does not.Settings.timeout > 3with"5"works by accident, butSettings.timeout + 1raises. - Nested
ENVseparators differ per library. Anyway Config uses__by default for nesting; the Config gem uses.unless you change it. Pick one convention across all services and document it. - Frozen config surprises gem authors. dry-configurable freezes the config after class load, so an initializer that mutates it later raises
FrozenError. Useconfigureinside ato_preparehook instead. - Local override files leak into CI.
settings.local.ymlandsettings/#{env}.local.ymlare convenient locally and dangerous when a CI image copies the working directory. Add them to.dockerignore. - Reloading is not free.
Settings.reload!re-reads every source synchronously. Calling it per request will show up in your p99 before it shows up in your logs. - Health checks that only check the process. A Rails app with a missing API key will happily return 200 on
/up. Validate the config object, not the socket.
Why This Matters for Self-Hosted Ruby Apps
Configuration discipline is the difference between a self-hosted app you can hand to a colleague and one that only runs on the machine where it was born. If you are deploying Ruby services on your own hardware, the config layer is also your upgrade path: a schema you can validate at boot is what lets you change an image tag without reading a changelog for an hour.
Related reading on this site: our Ruby ORM comparison covers the data layer that these config objects usually feed, the Ruby validation libraries guide shows how far the dry-rb ecosystem goes beyond settings, and the Ruby logging comparison explains how to emit the config values you actually need when something breaks.

FAQ
Which Ruby configuration library should I use in 2026?
For a gem or a plain Ruby service object, use dry-configurable: it keeps config namespaced to the class, supports inheritance, and has no Rails dependency. For a Rails app that needs YAML, credentials, and ENV merged, use Anyway Config. Use the Config gem only when you want a global Settings object and accept that nothing is validated.
Does the Config gem support environment variable overrides?
Yes, but you must enable it. Set config.use_env = true in config/initializers/config.rb, and set env_prefix and env_separator explicitly — the default separator is a dot, which cannot be exported in bash. Nested keys use the separator, so SETTINGS__SMTP__PORT maps to Settings.smtp.port.
How does Anyway Config order its configuration sources?
From lowest to highest priority: the YAML file (config/<name>.yml, namespaced by Rails environment), Rails secrets for Rails versions below 7.1, Rails credentials, then environment variables prefixed with the config name. Values passed directly to the constructor override all of them.
Can I reload configuration without restarting a Rails app?
The Config gem exposes Settings.reload!, and Anyway Config exposes reload! on config instances. Both re-read sources synchronously. In a multi-process deployment you must trigger the reload in every process, and in Kubernetes you must roll the deployment, because ConfigMap changes do not restart pods.
Is dry-configurable suitable for a large application?
It is suitable for the config schema itself, but it is not a configuration loader. There is no YAML layering, no ENV prefix convention, and no per-environment file support. Teams usually pair it with their own bootstrap that reads environment variables and calls configure, which is reasonable for a gem and a maintenance burden for a monolith.
What is the main risk of using a global Settings constant?
Test pollution and silent nil values. Because every example shares the same constant, a mutation in one test leaks into the next, and a typo returns nil instead of raising. If you use the Config gem, call Settings.reload! in a before hook and add explicit presence checks at boot.
💰 想测试你的市场判断力?我用 Polymarket 做预测市场交易——这是全球最大的预测市场平台,从大选结果到技术监管时间线,什么都可以押注。和赌博不同,这是真正的信息市场:你懂的信息越多,胜率越高。我靠预测技术相关事件的走向已经赚了不少。用我的邀请链接注册:Polymarket.com