dotenvy-rust

Loads environment variables from .env files in Rust applications using dotenvy.

2|Updated May 16, 2026
One-click install
npx skills add https://github.com/avbel/ai-skills --skill dotenvy-rust-avbel
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dotenvy-rust
Source: https://github.com/avbel/ai-skills/tree/main/skills/dotenvy-rust
Command: npx skills add https://github.com/avbel/ai-skills --skill dotenvy-rust-avbel

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Rust developers need a consistent way to load configuration from .env files without relying on the unmaintained dotenv crate, and must avoid common mistakes like loading after env::var calls or accidentally overriding production variables. ## Core Features & Use Cases - Flexible Loading Functions: Covers dotenv(), dotenv_override(), from_path(), from_filename(), and from_read() with clear guidance on override versus non-override behavior. - Iteration and Access Patterns: Shows how to iterate over key-value pairs with dotenv_iter() and safely parse typed values with std::env. - Use Case: A developer building an Axum web service needs DATABASE_URL and PORT loaded from .env in development but from real environment variables in production; this Skill provides the exact loading order, error handling patterns, and .gitignore practices to do it correctly. ## Quick Start Ask the agent to set up dotenvy in your Rust project so it loads a .env file at startup and reads DATABASE_URL and PORT with sensible defaults.

Frequently Asked Questions about dotenvy-rust

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I load a .env file in Rust?▼

Add dotenvy = "0.15" to Cargo.toml and call dotenvy::dotenv().ok() at the start of main before any env::var calls. The .ok() makes the .env file optional so missing files do not crash the application.

What is the difference between dotenv and dotenvy crates?▼

The original dotenv crate is unmaintained and abandoned. Dotenvy is the actively maintained fork with the same API, so replace dotenv with dotenvy in Cargo.toml for ongoing support and fixes.

Does dotenvy support variable substitution like $VAR in .env files?▼

No, dotenvy does not support variable substitution; values containing $VAR are stored literally. Use crates like shellexpand or envsubst if you need expansion of variables within .env values.

Why are my .env values not overriding existing environment variables?▼

The default dotenv() function does not override variables already set in the process environment. Use dotenv_override() or from_filename_override() when you explicitly want .env values to take priority.

How do I load different .env files per environment in Rust?▼

Use from_filename() with environment-specific files like .env.production or .env.test, selecting the file based on an APP_ENV variable. This keeps development, test, and production configurations separate.