LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

direnv

per-directory environment variable manager

TLDR

Enable direnv in your shell (add to shell config)
$ eval "$(direnv hook bash)"
copy
Create a new .envrc file
$ direnv edit .
copy
Allow the current directory's .envrc
$ direnv allow
copy
Deny/revoke an .envrc
$ direnv deny
copy
Reload the current environment
$ direnv reload
copy
Export current environment as shell commands
$ direnv export bash
copy
Show environment diff when changing directories
$ direnv status
copy
Print the current .envrc being used
$ direnv show
copy

SYNOPSIS

direnv [command] [arguments]

DESCRIPTION

direnv is an environment switcher that loads and unloads environment variables based on the current directory. When you enter a directory containing an .envrc file, direnv automatically exports its variables into your shell. When you leave, it unloads them.The .envrc file is a bash script that typically sets environment variables using export. Direnv provides a standard library of functions for common tasks like setting PATH, loading .env files, using nix-shell, or activating Python virtual environments.For security, .envrc files must be explicitly allowed before they're executed. This prevents malicious code from running when entering untrusted directories. The allow command whitelists a file based on its content hash; any change requires re-approval.Integration requires adding a shell hook to your configuration (e.g., ~/.bashrc). The hook modifies the prompt to show when direnv is active and handles automatic loading/unloading. Direnv supports bash, zsh, fish, tcsh, elvish, and other shells.Common use cases include project-specific environment variables, automatic virtual environment activation, and development environment configuration.

PARAMETERS

allow [path]

Approve an .envrc file to be loaded. Security measure to prevent executing arbitrary code.
deny [path]
Revoke approval for an .envrc file.
edit [path]
Open .envrc in $EDITOR and allow it after editing.
reload
Manually reload the current directory's environment.
status
Show direnv's current status and active .envrc.
export shell
Export the current environment for the specified shell (bash, zsh, fish, etc.).
hook shell
Print the shell hook code to enable direnv.
show
Display the currently loaded .envrc file.
version
Print direnv version.
prune
Remove old allowed file entries.
fetchurl url [integrity]
Fetch a URL with caching and optional integrity check.
stdlib
Print the stdlib functions available in .envrc.

CONFIGURATION

.envrc

Per-directory environment configuration script loaded when entering the directory.
~/.config/direnv/direnv.toml
Global direnv configuration for whitelist and settings.
~/.config/direnv/direnvrc
Global shared functions and settings available to all .envrc files.

INSTALL

sudo apt install direnv
copy
sudo dnf install direnv
copy
sudo pacman -S direnv
copy
sudo apk add direnv
copy
sudo zypper install direnv
copy
brew install direnv
copy
nix profile install nixpkgs#direnv
copy

CAVEATS

Shell hook must be added to config for automatic operation. .envrc files must be explicitly allowed (security feature). Changes to .envrc require re-allowing. Some shell features may not work identically in .envrc. Large environments may cause slight delay when changing directories.

HISTORY

direnv was created by Jonas Pfenniger (zimbatm) around 2013 to solve the problem of managing per-project environment configurations. It was inspired by the need to switch between different development environments without manually sourcing files. The tool has become popular in the DevOps and development communities, especially with nix integration.

SEE ALSO

env(1), export(1), nix-shell(1), virtualenv(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid