.zshenv not sourced on ssh login?
zshenv
is indeed read by every instance of the shell, but it is read first, before anything else. Your $PATH
is probably getting reset in zprofile
(~/.zprofile
or /etc/zprofile
, ...).
zshenv
is not a good place to set your $PATH
. It belongs in zprofile
, which has the job of setting up the environment upon login. Setting environment variables in zshenv
means among other things that they will get clobbered when running simple zsh
subshells or zsh
scripts within one session.
Related videos on Youtube
Wayne Werner
I'm a husband to my beautiful wife, father to our children, Computer Science graduate from University of Central Arkansas. I love my wife, our children, computers, playing guitar (especially singing/playing for my wife and/or kids), bicycling (including taking my kids for rides in my bike trailer), woodworking, airbrushing, digital and traditional artistry, playing games with my family (traditional and digital), my poor Chevette that I had to sell, throwing knives, firearms, knot tying, rope making, whip making, and really just learning new stuff in general. If I don't know about it I probably want to learn about it, if only so I can make informed decisions about it. My three favorite programming languages are Python, Lisp, and Assembly (though I'm not sure about the order of those last two languages...). I think the CANSPAM act is one of the dumbest pieces of legislation in the history of the universe I love Python and HTML+Javascript. I'm #SOreadytohelp (I really want a t-shirt, what can I say?)
Updated on September 18, 2022Comments
-
Wayne Werner over 1 year
According to the docs
.zshenv
is sourced on all invocations of the shell, unless the -f option is set. It should contain commands to set the command search path, plus other important environment variables..zshenv
should not contain commands that produce output or assume the shell is attached to a tty.Okay, cool, so I would assume that logging in via ssh is considered an invocation of zsh... but maybe not?
wayne@arglefraster ~ ⚘ echo $PATH 10:01:17 /usr/local/heroku/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl wayne@arglefraster ~ ⚘ zsh 10:01:20 e% wayne@arglefraster ~ ⚘ echo $PATH 10:01:24 /usr/local/heroku/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/wayne/.rvm/bin:/home/wayne/.bin:/home/wayne/.local/bin
Those extra bits of path are added in my
.zshenv
file.Is this normal, or do I have something wonky going on? Should I move my PATH modifications elsewhere?
-
Jakuje about 8 yearsYou have
zsh
as your default shell in/etc/passd
or you start it somehow different? -
Wayne Werner about 8 years@Jakuje almost added this to the question:
wayne:x:1000:100::/home/wayne:/bin/zsh
-
thrig about 8 yearsUse
zsh -o SOURCE_TRACE
to confirm what files are being read, and thenzsh -x
to see what configuration is done, in particular forPATH
, in the event something else is trampling the.zshenv
changes.
-
-
Wayne Werner about 8 yearsWell, it definitely wasn't getting reset in
~/.zprofile
or/etc/zprofile
, as I have neither of those files. Nor~/.zshrc
, as there's noPATH
variable there. But, setting the PATH in~/.zprofile
does appear to work properly. Following @thrig's comment, it may have been the virtualenvwrapper, though it seems strange that it would totally clobber thePATH
-
Leonard over 3 years