I'm using zsh and I'm trying to add a new entry (/home/david/pear/bin
) to the PATH
variable but I don't know how.
The thing that confuses me the most is that there's not a single reference to a PATH
variable in my ~/.zshrc
file, but doing echo $PATH
returns:
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
So a PATH
variable is being set somewhere.
To make the path variable persistent changes, we can use the shell configuration files loaded at each shell startup. In Bash, you can add the $PATH variable in the ~/. bashrc file. If you are on ZSH, you can add the $PATH in the ~/.
To add a path to the PATH environment variableIn the System dialog box, click Advanced system settings. On the Advanced tab of the System Properties dialog box, click Environment Variables. In the System Variables box of the Environment Variables dialog box, scroll to Path and select it.
Actually, using ZSH allows you to use special mapping of environment variables. So you can simply do:
# append path+=('/home/david/pear/bin') # or prepend path=('/home/david/pear/bin' $path) # export to sub-processes (make it inherited by child processes) export PATH
For me that's a very neat feature which can be propagated to other variables. Example:
typeset -T LD_LIBRARY_PATH ld_library_path :
Here, add this line to .zshrc
:
export PATH=/home/david/pear/bin:$PATH
EDIT: This does work, but ony's answer below is better, as it takes advantage of the structured interface ZSH provides for variables like $PATH
. This approach is standard for bash
, but as far as I know, there is no reason to use it when ZSH provides better alternatives.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With