user2453911
user2453911

Reputation: 57

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.

Upvotes: 2

Views: 9457

Answers (3)

mklement0
mklement0

Reputation: 437032

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.

Upvotes: 3

Mark Setchell
Mark Setchell

Reputation: 207335

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.

Upvotes: 2

a14m
a14m

Reputation: 8055

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

Upvotes: 1

Related Questions