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!
Top comments (0)