Terminal PATH has disappeared OSX - how to reset? - terminal

Something has happened to my $PATH variable -- how do i reset it to its initial settings?
If I run the command
$ cat /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
Then this is all correct. But when I run the command
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/sdev/Library/Enthought/Canopy_64bit/User/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/bin:/usr/bin:/usr/bin:/bin
I tried to fix this by using
export pathname
Need to restore to what it ought to be: I should just have this pathname when i run echo $PATH. I uninstalled Canopy which I thought would solve the problem.
/usr/bin

If you want to reset your PATH back to just /usr/bin/ put this in ~/.bash_rc
export PATH="/usr/bin/"
Or whatever you want between the quotes. Then you can run source ~/.bash_rc in terminal and the path will be set to what you set it as in .bash_rc.

Related

What is the right file where add search paths to the zsh enviroment variable `PATH` on macOS

I just compiled Ruby from source and it is located into /usr/local/ruby
In order to access Ruby's executables I edited ~/.zshenv adding /usr/local/ruby/bin to the export PATH directive:
export PATH=/usr/local/ruby/bin:/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:$PATH
^^^^^^^^^^^^^^^^^^^^
However restarting the terminal and running which ruby still returns macOS's default /usr/bin/ruby
In fact inspecting PATH reveals:
% echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/usr/local/ruby/bin:/usr/local/mysql/bin:/usr/local/sbin:
So after my ~/.zshenv is excecuted another configuration file prepends /usr/bin to PATH.
Where does this happen?
I would expect to find /usr/bin already in PATH when .zshenv is processed (resulting in having this path at the end of the environment variable).
What I am missing?
I checked and there are no other zsh configuration files in my home directory, just .zshenv;
I checked /etc too and found
zprofile
zshrc
zshrc_Apple_Terminal
but none of those do alter the PATH variable
on /etc/paths
I have
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
but again, shouldn't be PATH already set with those paths when .zshenv is processed ?
I would not trust apple to leave your /etc/paths directory alone, it's in their scope. Unless you have a need to manage this on a multiple person level, I would stick to changes in ~. For quick impact, I just add exports to .zshrc, and this is where I have my rvm bin directory added to my path.
The right place to alter PATH by appending user's search directories is ~/.zshrc that is sourced last.
This solution is based on the answers and comments to this question, other answers and comments to my question.
 
 
Following #Philippe advice I noticed actually .zshenv is sourced first, before any other configuration file/script.
After reading a post on the Zsh Mailing List Archive I put my PATH setting directives into ~/.zpath
Then ~/.zpath has to be sourced from ~/.zshenv when not in a login shell:
if [[ $SHLVL == 1 && ! -o LOGIN ]]; then
source ~/.zpath
fi
And from ~/.zprofile that is executed only when in a login shell.
source ~/.zpath
Alternatively o̲n̲ ̲m̲a̲c̲O̲S̲ it possible to just edit directly /etc/paths
/usr/local/mysql/bin
/usr/local/ruby/bin
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin

The system does not store the path which I have set in .bash_profile

I have placed this line in my .bash_profile.
export PATH="$PATH:/Users/margrietpronk/Developer/flutter/bin"
~
~
".bash_profile" 1L, 63C
Every time I restart my Mac, the path is not there. When I add this path manually, by the same command, then the path is known.
without adding it manually, when I put in echo $path, it shows:
Margrietje#iMac-van-MG ~ % echo $path
/usr/local/bin /usr/bin /bin /usr/sbin /sbin
when I add the command manually, it says:
Margrietje#iMac-van-MG ~ % echo $path
/usr/local/bin /usr/bin /bin /usr/sbin /sbin /Users/margrietpronk/Developer/flutter/bin
Then the path is working.
How can I fix this? I thought it has to do with the name "Margrietje" before the # ???
You tagged your question bash, but the fact that echo $path outputs the PATH as array, indicates that you are not using bash. My guess is that you are running Zsh, because in Zsh, PATH and path are kept in sync. You can verify this by doing a
echo $BASH_VERSION
and
echo $ZSH_VERSION
Of course if you do run Zsh, changing .bash_profile has no effect, and the changes should go into .zshrc.
I have switched back to the zsh shell, as advised by #chepner
First I had to make the file .zshrc, because it wasn't there. I have edit it explained here: https://superuser.com/questions/886132/where-is-the-zshrc-file-on-mac
I have put in the path for flutter:
export PATH="$PATH:/Users/margrietpronk/Developer/flutter/bin"
Then I switched in the terminal to the zsh shell:
chsh -s /bin/zsh
The path is working now. Hope this is helping somebody with the same problem as I had.

Messed system paths and cannot start apps

I edited /etc/paths, putting the local directories on top, and now I cannot run commands in terminal, including sudo, and am afraid this will affect the system outside terminal.
Trying to solve it, I have commented out everything and sourced .bash_profile and .bashrc, there is nothing under /etc/paths.d/, and /etc/paths is now:
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
Yet the problem remains:
$ echo $PATH
/Volumes/Macintosh HD/Users/jsmm/.wp-cli/bin:/usr/local/bin:/Volumes/Macintosh HD/Users/jsmm/bin:/Volumes/Macintosh HD/Users/jsmm/.wp-cli/bin:/usr/local/bin:/usr/local/sbin:/Applications/Postgres.app/Contents/MacOS/bin:/usr/local/mysql/bin:/usr/local/bin:/usr/local/sbin:/Applications/Postgres.app/Contents/MacOS/bin:/usr/local/mysql/bin:/usr/local/bin:/usr/local/sbin:/Applications/Postgres.app/Contents/MacOS/bin:/usr/local/mysql/bin:/usr/local/bin:/usr/local/sbin:/Applications/Postgres.app/Contents/MacOS/bin:/usr/local/mysql/bin:/Volumes/Macintosh:/Volumes/Macintosh:/Volumes/Macintosh HD/Users/jsmm/.wp-cli/bin
And:
$ /usr/libexec/path_helper -s
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/Volumes/Macintosh HD/Users/jsmm/.wp-cli/bin:/Volumes/Macintosh HD/Users/jsmm/bin:/usr/local/sbin:/Applications/Postgres.app/Contents/MacOS/bin:/usr/local/mysql/bin:/Volumes/Macintosh"; export PATH;
System is Mac OS X 10.8 Mountain Lion. Looking forward to your help,

How can I see the current value of my $PATH variable on OS X?

$ $PATH
returns:
-bash: /usr/local/share/npm/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/local/sbin:~/bin:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin: No such file or directory
This seems quite ugly and might be giving me issues with getting Homebrew up and running as well.
You need to use the command echo $PATH to display the PATH variable or you can just execute set or env to display all of your environment variables.
By typing $PATH you tried to run your PATH variable contents as a command name.
Bash displayed the contents of your path any way. Based on your output the following directories will be searched in the following order:
/usr/local/share/npm/bin
/Library/Frameworks/Python.framework/Versions/2.7/bin
/usr/local/bin
/usr/local/sbin
~/bin
/Library/Frameworks/Python.framework/Versions/Current/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
/opt/X11/bin
/usr/local/git/bin
To me this list appears to be complete.
By entering $PATH on its own at the command prompt, you're trying to run it. This isn't like Windows where you can get your path output by simply typing path.
If you want to see what the path is, simply echo it:
echo $PATH
To list out the paths as individual lines, you could use:
echo "${PATH//:/\n}"
Use the command:
echo $PATH
and you will see all path:
/Users/name/.rvm/gems/ruby-2.5.1#pe/bin:/Users/name/.rvm/gems/ruby-2.5.1#global/bin:/Users/sasha/.rvm/rubies/ruby-2.5.1/bin:/Users/sasha/.rvm/bin:
for MacOS, make sure you know where the GO install
export GOPATH=/usr/local/go
PATH=$PATH:$GOPATH/bin

How to modify PATH for Homebrew?

Trying to install ruby 1.9.3, read that I need to install homebrew first. Ran brew doctor, and it's giving me a bunch of warnings. One of which is:
Warning: /usr/bin occurs before /usr/local/bin This means that
system-provided programs will be used instead of those provided by
Homebrew. The following tools exist at both paths:
easy_install
easy_install-2.6
Consider amending your PATH so that /usr/local/bin is ahead of
/usr/bin in your PATH.
How does one do what it's asking here?
open your /etc/paths file, put /usr/local/bin on top of /usr/bin
$ sudo vi /etc/paths
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
and Restart the terminal, #mmel
There are many ways to update your path. Jun1st answer works great. Another method is to augment your .bash_profile to have:
export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
The line above places /usr/local/bin and /usr/local/sbin in front of your $PATH. Once you source your .bash_profile or start a new terminal you can verify your path by echo'ing it out.
$ echo $PATH
/usr/local/bin:/usr/local/sbin:/Users/<your account>/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
Once satisfied with the result running $ brew doctor again should no longer produce your error.
This blog post helped me out in resolving issues I ran into. http://moncefbelyamani.com/how-to-install-xcode-homebrew-git-rvm-ruby-on-mac/
Just run the following line in your favorite terminal application:
echo export PATH="/usr/local/bin:$PATH" >> ~/.bash_profile
Restart your terminal and run
brew doctor
the issue should be resolved
open bash profile in textEdit
open -e .bash_profile
Edit file or paste in front of PATH
export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin:/usr/local/sbin:~/bin
save & close the file
*To open .bash_profile directly open textEdit > file > recent
To avoid unnecessary duplication, I added the following to my ~/.bash_profile
case ":$PATH:" in
*:/usr/local/bin:*) ;; # do nothing if $PATH already contains /usr/local/bin
*) PATH=/usr/local/bin:$PATH ;; # in every other case, add it to the front
esac
Credit: https://superuser.com/a/580611

Resources