Per-Directory Environments With direnv
Automatically set and unset environment variables as you cd between projects.
Create an .envrc, run direnv allow once, and it loads whenever you enter the directory.
01Command
Command
$ direnv allow02What it does
direnv hooks into your shell and evaluates the .envrc in each directory, exporting variables for that project and removing them on exit. The explicit allow step means a cloned repository cannot silently execute code until you review it.
03Risk
!Warning: Never run direnv allow on an .envrc you have not read; it executes arbitrary shell code.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Debian package: direnvEvidence: Debian packages direnv, which loads and unloads .envrc files when entering directories.
- direnvEvidence: Debian packages direnv, which loads and unloads .envrc files when entering directories.
Last verified: 2026-09-22 · Category: Developer