How to modify PATH for Homebrew? - ruby

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

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

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.

Setting PATH on OS X 10.9 is not working

I have searched all posts regarding PATH issues on Mac, but have not found an answer to mine.
I want to get /usr/local/bin to be searched first. I used homebrews example but it did not work. I created the .bash_profile file and put in:
export PATH="/usr/local/bin:$PATH"
As homebrew says except this seems to remove the standard commands for me with ls, cd, etc not working. I want it to search this folder first. I found the /etc/paths file and saw that it /usr/local/bin is located last.
Following instructions found here not to mess with the path file, I removed the change I made to .bash_profile and was able to get it to work (brew doctor is successful) with putting in
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I have tested this on two different Macs, and neither accepts appending the $PATH. Doing some research it seems that there is a path_helper file which calls stuff which may have changed in OS x 10.9. Is there a way to get the appending to work? I have tried it with the quotes and without and neither works. And each time I have restarted terminal or tried the source ~/.bash_profile command
I would prefer to not rewrite the whole path in .bash_profile, or at least know why appending it is not working.
After some investigation it turns out that the problem may have been how file ~/.bash_profile was created - it may not have been a plain-text file (due to use of TextEdit).
Recreating it with a plain-text editor (Sublime Text) solved the problem.
Follow-up question by the OP:
As for prepending /usr/local/bin without having it appear twice in $PATH:
export PATH="/usr/local/bin:${PATH/:\/usr\/local\/bin/}"
${PATH/:\/usr\/local\/bin/}, using bash's parameter/variable expansion, removes /usr/local/bin, if present, from the existing $PATH.
I had a similar problem after installing homebrew.
In the end, it came down to the fact that brew doctor was suggesting I modify ~/.bash_profile when all my usual (old) settiings were in ~/.profile. If you read the bash manpage though it tells you that bash first reads /etc/profile and then THE FIRST ONE OF ~/.bash_profile, ~/.bash_login, and ~/.profile - not all of them!
What I am saying is to agglomerate all your setttings in ONE of thos e files only.
edit the /etc/paths to look like
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
if it didn't work then add export PATH="/usr/local/bin:$PATH" to the .bash_profile and it should work...

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 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

Resources