I have recently installed PIPX on MAC running Big Sur and ZSH shell. During the install it prompted for the following to be added to the .zshrc file....

# Created by `pipx` on 2021-03-20 14:22:23
export PATH="$PATH:/Users/xxxx/.local/bin"
eval "$(register-python-argcomplete pipx)"

Running echo $PATH showed /Users/xxxx/.local/bin added to the end of my PATH variable. However, when I close the terminal and open up a new session, running echo $PATH now shows the location duplicated at the end of the PATH :/Users/xxxx/.local/bin:/Users/xxxx/.local/bin

Opening and closing new terminal sessions doesn't seem to create any more additions to PATH it just remains at these 2 entries....

I have run typeset -U PATH path to remove the duplicate but each time I open up new terminal sessions it just duplicates again.

Does anybody know how I can stop this from happening.....I would really like to keep my PATH variable as clean as possible.

  • Did you try removing the export PATH=... all together and see if you end up with just one? Are you sure you don't already have a similar line in your file? Mar 21 at 16:14
  • Try from a subshell and see if it duplicates in any further. Try couple of subshells in fact. You may have to put thr path declaration in .profile and log out and login once. Mar 21 at 16:26
  • Try running zsh --login --xtrace to see where the path is added twice. BTW, you may want to replace the first line with path+=( ~/.local/bin ) Mar 21 at 16:38
  • Thank you for your advice.....@Andy Dalton, yes I did end up with just one......@Just Khaithang, it did not duplicate further when opening sub shells.....@ Stephane Chazelas, I ran 'zsh --login --xtrace'....wow, I had not run that before, it generated too much info to review !!! I have now found the source of the problem....I have amended my main post to reflect. @Stephane - why change to path+=( ~/.local/bin ) ....what is the benefit of that ?
    – KB_cov
    Mar 21 at 17:07
  • path+=( ~/.local/bin ) avoids hardcoding the path of your home directory, and if $PATH was previously empty makes it PATH=/Users/xxxx/.local/bin instead of PATH=:/Users/xxxx/.local/bin (which you wouldn't want to do as that puts the current working directory at the head of the PATH search). Mar 21 at 17:11

I have now found the source of duplication. Whilst during the install of pipx it requested that I add the stated directory to the path to the .zshrc file. However, it appears that somehow it also automatically added the export path statement to the .zprofile file.

Now I just need to decide if there is any value leaving it on both files or removing it from one of them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.