TIDBIT: get direnv to use .env

charlesloder

Charles Loder

Posted on August 17, 2022

TIDBIT: get direnv to use .env

direnv is a great tool for loading environment variables on a per-project basis.

The one catch is that it loads .envrc files by default and not .env. I found their instructions on how to load an .env a little unclear for a new developer like myself so below I'll show what to do.

I'm assuming:

create a config

First, create a config directory for direnv



mkdir ~/.config/direnv


Enter fullscreen mode Exit fullscreen mode

Then create a config file



touch ~/.config/direnv/direnv.toml


Enter fullscreen mode Exit fullscreen mode

configure

Open the config, and add



[global]
load_dotenv = true


Enter fullscreen mode Exit fullscreen mode

Save, and restart your shell



exec $SHELL


Enter fullscreen mode Exit fullscreen mode

That's it!

Now, when you go to a project with a .env file, you can simply run



direnv allow


Enter fullscreen mode Exit fullscreen mode

It will load the .env instead of just looking for .envrc

I hope this helps someone else!

💖 💪 🙅 🚩
charlesloder
Charles Loder

Posted on August 17, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

TIDBIT: get direnv to use .env
devops TIDBIT: get direnv to use .env

August 17, 2022