Per-Directory Environments With direnv

Automatically set and unset environment variables as you cd between projects.

LinuxautomationshellconfigLow risk
Create an .envrc, run direnv allow once, and it loads whenever you enter the directory.

01Command

Command
$ direnv allow

02What 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

RiskLow risk
Requirementssudo apt install direnv
!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: direnv
    Debian · vendor-doc · 2026-09-20
    Evidence: Debian packages direnv, which loads and unloads .envrc files when entering directories.
  • direnv
    Official project · vendor-doc · 2026-09-20
    Evidence: Debian packages direnv, which loads and unloads .envrc files when entering directories.

Last verified: 2026-09-22 · Category: Developer

06Related solutions