PATH variable in .zshenv or .zshrc - path

My setup is zsh 5.0.5 in arch linux
I have set the PATH variable as below in .zshenv
typeset -U path
path=(~/bin $path)
DW=$HOME/Downloads
but it didn't work. print $PATH shows only
/usr/local/bin:/usr/bin:/usr/bin/vendor_perl:/usr/bin/core_perl
.zshenv was read, because I could see DW variable is set. Only PATH variable isn't set. And what I don't understand is, after rename the .zshenv to .zshrc, PATH variable just works as intended.
Need any special treatment setting environment variables in .zshenv?

I just encountered this problem myself, and the real answer is that Zsh on Arch sources /etc/profile – which overwrites and exports PATH – after having sourced ~/.zshenv.
See: https://wiki.archlinux.org/index.php/Zsh#Configuration_files

It seems that when you have macos or some linux distros there is a canonical solution to the problem which involves /etc/paths or /etc/paths.d. You should be letting /usr/libexec/path_helper construct your path for you using configuration files.
This immediately solved the problem in all places for me.

I've got the same problem. The cause was my .zshrc (fresh install of oh-my-zsh) override PATH (ignoring existing value):
export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl"
To fix, I comment the line.

Related

macOS Catalina: bash → zsh? Where to add new path variables

Ever since the latest macOS update, I've been using zsh as the default shell. However, all my PATH variables are set up in ~/.bash_profile.
~/.zprofile and ~/.zshenv doesn't exist, and ~/.zshrc has no path variables
My question is: where should I actually put my path variables in the future?
Everything seems to work fine (GO Path, Python, Node paths - none of them are in the zsh profile though..)

nix-env and nix-build not found after installation (debian buster)

after the installation following the instructions with
curl https://nixos.org/nix/install | sh
and logout/login, nix-env and nix-build are not found.
I had the problem with debian stretch and now with buster. What am I doing wrong?
The nix manual instructs to execute
source ~/.nix-profile/etc/profile.d/nix.sh
but the instructions printed after the execution say to do (I do not remember exactly)
./~/.nix-profile/etc/profile.d/nix.sh
and the same command is inserted into ~/.profile. The cause of the problem is the difference between . and source (see this superuser question). The script is setting up the $PATH variable in the environment and has the desired effect wtih source but no effect with . (which operates in its own shell and closes it at the end).
Cure:
change the line in .profile (or better move it to .bashrc) to
if [ -e /home/xxx/.nix-profile/etc/profile.d/nix.sh ]; then source /home/xxx/.nix-profile/etc/profile.d/nix.sh; fi
(xxx is your user name),
You need to add this recommended script.
For me only setting $PATH like this worked (in .profile)
export PATH="$PATH:/nix/var/nix/profiles/default/bin"

How to find the source of $PATH?

I'm using a Centos 7 server. I'm entering the command echo $PATH and trying to figure out where it's getting the path that it's putting out. The path doesn't match what's in my .bash_profile, and there is no .bashrc file. How do I find out where my current $PATH is being sourced from?
The Default values for .bashrc and $PATH are stored in files /etc/bashrc and /etc/profile. These files are used by shell and kernel for setting default values for proper functioning of the server.
I would advise not to change any values here, as it might cause abnormal behavior in the server.

Default PATH variable set with .bash_profile empty

I remember after a fresh install of os x, when i did a echo $PATH in the terminal, it responded with a blank line. Now after installing some tools over time, the $PATH variable has /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin value although my .bash_profile is blank. I was wondering where this value is being set?
Plausible candidates would be /etc/profile and /etc/bashrc; there's also /etc/paths and /etc/paths.d to look at. You might also need to look at $HOME/.profile and $HOME/.bashrc. There might be some other places that bash looks too.
As of macOS Catalina, Mac defaults the shell to zsh (Z shell). This type of shell uses .zprofile instead of .bash_profile. To check if you are on bash or zsh, run echo $SHELL. If the result is bin/zsh, you are on zsh. In which case edit your ~/.zprofile for env variables.

How do you update your "HOMEBREW_TEMP" environmental variable?

I'm getting the following error when running "brew doctor":
Error: Your Cellar and TEMP directories are on different volumes.
OS X won't move relative symlinks across volumes unless the target file already
exists. Brews known to be affected by this are Git and Narwhal.
You should set the "HOMEBREW_TEMP" environmental variable to a suitable
directory on the same volume as your Cellar
How do I set this variable? And what should I set it to? I can't seem to find anything about this when googling.
You set your HOMEBREW_TEMP by editing your ~/.bash_profile and doing this:
export HOMEBREW_TEMP=/new/path
Then start a new shell.
Alternatively type that into any already open shell.
Google setting shell environment variables for further information.
I fixed this problem by setting the path of the temp folder manualy.
First i created a folder temp in /usr/local/ and then added the following to my zsh file nano ~/.zshrc
export HOMEBREW_TEMP=/usr/local/temp
Same problem occurred to me. I actually have configured separate disk in memory for /private/tmp. Hope that's why this error occurred.
To solve this issue, create a directory somewhere, like /usr/local/brew_temp
Then add following line to file ~/.profile. If file doesn't exist create that file
export HOMEBREW_TEMP=/usr/local/brew_temp
In each restart it will set the HOMEBREW_TEMP environment variable to that path. After setting these option either you can restart OS X or run following in command line if you don't want to restart
. ~/.profile
For anyone that runs into this in the future, try restarting your computer and then running brew doctor again. That fixed it for me.

Resources