direnv
A shell extension that loads environment variables per-directory.
direnv loads and unloads environment variables based on the current working directory. When you cd into a directory that contains a .envrc file (and you have approved it once with direnv allow), direnv injects the variables into your shell; when you cd out, they are automatically removed. The result is per- project tooling configuration without polluting the global shell environment.
Zimbatm (Jonas Pfenniger) started direnv around 2014. Standard .envrc helpers cover layout commands like layout python (auto- activate a virtualenv), layout node, source_up (inherit parents), and use nix or use flake (drop into a Nix shell), so most projects need only a one-line file.
direnv has become the standard way to manage per-project environment variables on Unix systems. The Nix and Home Manager communities lean on it heavily for development shells, and many dotfile setups in the modern Rust/Go/Node toolchain combine direnv with mise or asdf for runtime version selection.
Install
Debian/Ubuntu: sudo apt install direnv Fedora/RHEL: sudo dnf install direnv Arch: sudo pacman -S direnv macOS: brew install direnv
Authors
- Zimbatm (creator)