$linuxjunkies
>

direnv(1)

direnv is an environment switcher for the shell that loads and unloads environment variables based on the current directory.

UbuntuDebianFedoraArch

Synopsis

direnv [COMMAND] [ARGS]...

Description

direnv manages per-directory environment variables by reading a .envrc file in the current directory. When you cd into a directory with a .envrc, direnv automatically loads those variables; when you leave, it unloads them. This keeps your shell clean and project-specific configurations isolated.

direnv requires shell integration (bash, zsh, fish, etc.) added to your shell rc file. It uses an allow-list mechanism where each .envrc must be explicitly allowed before execution, preventing accidental code execution from untrusted directories.

Common options

FlagWhat it does
allowWhitelist a .envrc file so direnv will execute it
denyRemove a .envrc from the allow-list
statusShow the current environment and .envrc status
reloadForce reload of the current .envrc
exportExecute .envrc and print environment changes as shell commands
hook [SHELL]Print shell integration code for bash, zsh, fish, etc.
versionPrint direnv version
fetchurl URLDownload a file and print its hash (used in .envrc for remote scripts)

Examples

Whitelist the .envrc in the current directory after reviewing it with 'direnv status'

direnv allow

Create a .envrc that prepends /custom/bin to PATH and allow it

echo 'export PATH_prepend=/custom/bin' > .envrc && direnv allow

Display the current direnv state and which .envrc files are loaded

direnv status

Output the environment changes as bash commands (useful for testing .envrc)

direnv export bash

Review the .envrc file before allowing it (best practice for security)

cat .envrc

Add direnv integration to bash (typically placed in ~/.bashrc)

eval "$(direnv hook bash)"

Remove the current .envrc from the allow-list

direnv deny

Related commands