The ultimate environment switcher: direnv

February 2, 2017 · 1 minute to read · Linux, tools

I usually change a lot of workspaces during my workday. Generally, I have to load or unload different environments: python virtualenv, ruby gems, node modules…

It’s not very convenient to call the right executable or to change PATH variable (or others) when I switch projects.

Finally, I found an incredible tool for this task : direnv.

This tool is describe like

an environment switcher for the shell

Using

First, you need to install, and to enable it in your .bashrc. It can work on different shells: bash, zsh, fish and tcsh.

The next step is to create .envrc file in each workspace you need it. It will be loaded when you will change of directory.

Then you have to allow it by running another command direnv allow .envrc. It is a security guard, per example when you clone an untrusted repository.

This file can contain any bash commands. Lots of useful functions are also available.

References