Thursday, September 10, 2015

macos - How should I set the PATH variable on my Mac so the Hombrew-installed tools are found?


Trying to set up Homebrew on a new Mac (on previous Macs I would install packages from source).


The first package I tried to install was Git:


$ brew install git

Installation went OK, but which git still shows the one in /usr/bin/git that came along with Lion (I think?). And not the one in /usr/local/bin/git that was just installed.


$ echo $PATH
/Users/meltemi/.rvm/gems/ruby-1.9.2-p290@rails31/bin:/Users/meltemi/.rvm/gems/ruby-1.9.2-p290@global/bin:/Users/meltemi/.rvm/rubies/ruby-1.9.2-p290/bin:/Users/michael/.rvm/bin:/usr/local/mysql/bin:/opt/subversion/bin:/Developer/Additions/checker/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

As you can see /usr/bin defaults to before /usr/local/bin in the $PATH


So, I'm confused! I thought the point of HomeBrew (and something the creators seem to brag about) was that you don't have to mess with the $PATH variable!?!


So, what did I do wrong?


Answer



I found this related post to be very helpful. Instead of changing the $PATH variable, it just has you simply edit your /etc/paths file.


Homebrew wants me to amend my PATH; no clue how


As soon as I followed the directions and put /usr/local/bin above /usr/bin, my issues were resolved.



  1. On OS X, open Terminal

  2. Type the command: sudo vi /etc/paths

  3. Enter your password if you're asked for it

  4. You will see a list of paths. Edit them so that /usr/local/bin path is entered above the /usr/bin path

  5. *Save and quit

  6. Restart Terminal


Here's what mine looks like after I did that:


/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

*To save and quit type a colon (:), then type wq (to write and quit at the same time), followed by Enter.


You can also open the /etc/paths file in a graphical text editor and edit it that way.


Credit to fengd
over at Stack Overflow for his answer over there.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...