Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

$PATH issue

Hi, my son was trying to installing something using Homebrew and seems to have messed up PATH


So now


echo $PATH


results in this mess


/Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin /usr/bin /bin /usr/sbin /sbin:~/Library/Python/3.6/bin:~/Library/Python/2.7/bin:/usr/bin:/bin


I tried to reset it using


PATH=/bin:/usr/bin/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin


which seems to work when running echo $PATH again, but it doesn't save & reverts back.


How do I reset it correctly?


Mac mini, macOS 10.12

Posted on Oct 18, 2019 2:02 PM

Reply
9 replies

Oct 19, 2019 10:46 AM in response to VikingOSX

.bashrc is not normally read during a bash login, but rather when explicitly sourced by the bash login initialization script, or when an interactive subshell is started.


marc okem Look for one of the following files

  • .bash_profile
  • .bash_login
  • .profile

The first one you find is most likely where the broken PATH environment variable is export'ed. Make your fix in that file.


Unless you are using zsh after doing a Catalina install and following any instructions telling you to switch to zsh, then it would be a different initialization file.

Oct 22, 2019 5:06 PM in response to marc okem

Now echo $PATH results in
/usr/local/bin /usr/bin /bin /usr/sbin /sbin:~/Library/Python/3.6/bin:~/Library/Python/2.7/bin:/usr/bin:/bin


There should be colons between each path, and no spaces. I would expect a working PATH to look like:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:~/Library/Python/3.6/bin:~/Library/Python/2.7/bin:/usr/bin:/bin


Now looking at this, it seems you would have multiple copies of

  • /bin
  • /usr/bin

Because the 2nd copies of each of these is properly colon separated, the first ones are not missed, except in order the directories they are checked.


/usr/local/bin

/sbin

/usr/sbin


are not being search.


/usr/local/bin is often used by HomeBrew, and standard open source built binaries.


/sbin and /usr/sbin are where some of the admin commands and utilities are stored.


Oct 18, 2019 2:41 PM in response to marc okem

Here is what you place in the following hidden text files. The tilde (~) is an abbreviation for your home directory path.


Bash (default shell prior to Catalina)

~/.bash_profile

export PATH=".:/usr/local/bin:/usr/local/sbin:$PATH"
export MANPATH=".:/usr/local/share/man:/usr/share/man:$MANPATH"



Zsh (default shell in Catalina)

~/.zshrc

export PATH=".:/usr/local/bin:/usr/local/sbin:$PATH"
export MANPATH=".:/usr/local/share/man:/usr/share/man:$MANPATH"



To set those environment variables for the current Terminal session and respective SHELL:

source ~/.bashrc
# or
source ~/.zshrc


When Terminal is next launched, these PATHS will automatically get set.


I install Python using the Python.org installers. This precludes cluttering up the PATH statements with /Library references as the installer makes a link from the Framework binaries back into /usr/local/bin. Thus, if I have /usr/local/bin in my PATH, then all I have to do is run python3, and it automatically knows where its Framework is located and makes all of its packages available within the Python script.



Oct 22, 2019 10:49 AM in response to leroydouglas

Hi, thanks for all the help & the follow up.


I haven't personally tried Viking's recommendation yet as I have not seen my son & his computer for long enough to sit down and run through it.


I emailed him this page's advice & he messaged back that he had updated to Catalina & zsh (& that at least has updated PATH to something cleaner)


Now echo $PATH results in


/usr/local/bin /usr/bin /bin /usr/sbin /sbin:~/Library/Python/3.6/bin:~/Library/Python/2.7/bin:/usr/bin:/bin


he could not find .zshrc (or .bashrc) in his home directory path. He did find .bash_profile which, as Bob suggested, seems to be the where the broken variable is as it currently reads


# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH


Would Viking's recommended amendment from the above to


export PATH=".:/usr/local/bin:/usr/local/sbin:$PATH"
export MANPATH=".:/usr/local/share/man:/usr/share/man:$MANPATH"


still be the correct fix?


thanks again.


Oct 23, 2019 2:37 AM in response to marc okem

It looks like your son is mixing the path variable with the PATH variable. path is a array of search paths and PATH is a colon separated scalar of search paths. Both will sync with each other but should not be used together. I suggest that your son uses the path variable assignment instead of the PATH assignment. I would add this to .zshenv

path=($path ~/Library/Python/3.6/bin ~/Library/Python/2.7/bin)  

$PATH issue

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.