Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Direnv not loading environment when shell starts in a directory with .envrc

Imagine I am in a shell with the working directory set to a directory that contains an .envrc file. When I now open up a new tab in my terminal emulator, a new shell is launched into the same working directory as the original shell.

For some reason, the .envrc file is not loaded in this new shell. If manually exit the working directory and enter it again, the environment variables are then loaded.

Is there a way to make the variables load automatically when the shell is created?

I am running MacOS Mojave (10.14.4) with direnv 2.20.1, using bash as my shell. I am loading the direnv hooks through my .bashrc.

like image 635
aef Avatar asked Nov 24 '25 22:11

aef


2 Answers

I found in my zsh environment I needed to put export in front of each variable in .envrc

VAR=x

doesn't work

Instead, use:

export VAR=x
like image 53
Greg Pagendam-Turner Avatar answered Nov 27 '25 12:11

Greg Pagendam-Turner


Under macOS Mojave (and probably older versions), saving a .bashrc has no effect. Instead, use a .bash_profile.

like image 42
Neskews Avatar answered Nov 27 '25 13:11

Neskews