Linux/direnv: Difference between revisions
< Linux
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 8: | Line 8: | ||
eval "$(direnv hook bash)" | eval "$(direnv hook bash)" | ||
Allow config file: | |||
direnv allow . | |||
default env file:: | |||
.envrc | .envrc | ||
full bash script style | |||
Only if enabled in config: | |||
.env | |||
static key=var pairs | |||
Example sourcing a python environment: | Example sourcing a python environment: | ||
Latest revision as of 01:28, 18 November 2026
Loads variables from .envrc on cd into a directory and unloads them on cd out
https://pydevtools.com/handbook/reference/direnv/
sudo apt install direnv
# bash (~/.bashrc) eval "$(direnv hook bash)"
Allow config file:
direnv allow .
default env file::
.envrc full bash script style
Only if enabled in config:
.env static key=var pairs
Example sourcing a python environment:
.envrc source .venv/bin/activate
Built in python helper example (The built-in layout python helper goes one step further and creates the environment if it does not exist):
.envrc layout python python3.12
More examples:
.envrc export UV_PROJECT_ENVIRONMENT="$PWD/.venv" source "$UV_PROJECT_ENVIRONMENT/bin/activate"
warning
direnv: error /home/user/.src/project/.envrc is blocked. Run `direnv allow` to approve its content