smhk

Directory specific environment variables with direnv

direnv is a very simple but useful tool. Create a .envrc file that defines some environment variables, e.g.:

export MY_VAR=123
export SOMETHING_ELSE=blah

When you cd into that directory, the environment variables are loaded. When you cd out, they are unloaded.

Installation on Ubuntu §

On Ubuntu it’s as simple as sudo apt-get install direnv. Then add the following to your ~/.bashrc and restart your shell:

eval "$(direnv hook bash)"

Other distributions and shells §

It’s packaged on most distributions and supports all major shells.