Messed system paths and cannot start apps - macos

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,

Related

zsh with different $PATH in login and non-login shell. Behavior not as it is defined

edit This question was asked on a wrong premise. See at the end edit
I am working on a Mac with zsh and my $PATH is read not as it should, so that I have two versions of path. One with homebrew at the end and one with homebrew at the beginning.
My assumption is that the non-login shell is reading .zprofile although it shouldn't. I got the information about the ZSH startup scripts here Link.
Question: How do I get the same $PATH for homebrew in both shells?
Detailed:
I am using the MacOS terminal and the one integrated into PyCharm (IDE Software).
I have installed homebrew which puts eval "$(/opt/homebrew/bin/brew shellenv)" into the ~/.zprofile.
MacOS shell uses this this $PATH: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin:/opt/homebrew/sbin
PyCharm shell uses this as $PATH: /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
As you can see homebrew is at the beginning in one and at the and in the other.
MacOS Testing which shell is used with ps -o comm= $$
Terminal uses -zsh (I assume this as the login shell)
PyCharm uses /bin/zsh(I assume this is the non-login shell)
If I understand the startup scripts correctly then the non-login shell in PyCharm does not read .zprofile so it shouldn't be able to see the homebrew path and the MaxOS with the log-in shell should see the homebrew path at the beginning, because it reads ~/.zprofile first.
edit
It seems like the problem lies within tmux.
in ~/.zprofile is this line: eval "$(/opt/homebrew/bin/brew shellenv)"
after starting tmux, the zsh shows this $path: /usr/local/bin /usr/bin /bin /usr/sbin /sbin /opt/homebrew/bin /opt/homebrew/sbin
when tmux is not running zsh shows this $path: /opt/homebrew/bin /opt/homebrew/sbin /usr/local/bin /usr/bin /bin /usr/sbin /sbin
the order is switched.
solution
I used export PATH="/opt/homebrew/bin:$PATH" instead of eval "$(/opt/homebrew/bin/brew shellenv)" in the ~/.zprofile and now the order in $path is the same in tmux.

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.

Terminal PATH has disappeared OSX - how to reset?

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.

etc/paths modifications not taken into account in OS X Mountain Lion

I installed node.js, pip, rvm a few weeks ago. I just installed them and checked everything was working fine.
Yesterday, as I tried to install howdoi (https://github.com/gleitz/howdoi) using zsh via pip, I got a pip : command not found error message.
The echo $PATH command gave me this:
"rvm stuffs":/usr/bin:/bin:/usr/sbin:/sbin:
Then, I checked the etc/paths file:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
It looks like /usr/local/bin is in my etc/paths file but not in my path.
I temporarily fixed this with a temporary solution:
export PATH=$PATH:/etc/paths
This morning, I am looking for a permanent solution.
You could add this to your ~/.profile, ~/.bashrc, or ~/.bash_profile. In Terminal:
cat << EOF >> ~/.profile
PATH=/usr/local/bin:\$PATH; export PATH
EOF
Open a new Terminal (Command + N) and test the change:
echo $PATH

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