TIDBIT: get direnv to use .env
Charles Loder
Posted on August 17, 2022
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:
- you've installed
direnv
- you're on a mac or linux machine (sorry, Windows)
create a config
First, create a config directory for direnv
mkdir ~/.config/direnv
Then create a config file
touch ~/.config/direnv/direnv.toml
configure
Open the config, and add
[global]
load_dotenv = true
Save, and restart your shell
exec $SHELL
That's it!
Now, when you go to a project with a .env
file, you can simply run
direnv allow
It will load the .env
instead of just looking for .envrc
I hope this helps someone else!
💖 💪 🙅 🚩
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.