Practical examples of using
direnvto automatically configure project-specific development environments.
direnv is a shell extension that automatically loads and unloads environment variables when you enter or leave a directory. It’s perfect for managing things like:
- Language versions (e.g. Node.js, Python)
- Virtual environments
- Secret environment variables
- Project-specific setup
This repository includes examples of using direnv with popular development setups:
| Language | Tool | Folder |
|---|---|---|
| Python | virtualenv/pipenv | Python |
| Terraform | dotenv | Terraform |
| Node.js | nvm | Node |
Each folder contains:
-
A working
.envrcfile -
A
README.mdexplaining how it works and how to use it -
A bunch of examples
-
🛠️ Step 1 – Install direnv
direnv is packaged in most distributions already. See the installation documentation for details.
-
Brew macOS
brew install direnv
-
Debian/Ubuntu
sudo apt install direnv
-
Debian/Ubuntu
sudo apt install direnv
-
-
🧠 Step 2 – Hook direnv into your shell
echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc # or bash/fish
-
🔐 Step 3 – Trust the project directory
💡 Note: Run
direnv allowonly the first time you enter the project folder, or whenever you make changes to the.envrcfile.Navigate to your project folder
direnv allow
-
🔁 Step 4 – Automatic loading!
✅ Output on success
direnv: loading ~/my-project/.envrc direnv: export +VIRTUAL_ENV ~PATH
❌ Output on error
direnv: error ~/my-project/.envrc is blocked. Run `direnv allow` to approve its content
