Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm having difficulty setting up the PATH on my macbook pro.

I followed this link to modify my path variable.

Each time I start a new terminal I get a PATH pointing towards

/Applications/eclipse/apache-maven-3.0.5/bin

Even though the .bash_profile is as follows

EXPORT PATH=/usr/bin:$PATH
export PATH=/usr/local/bin:$PATH
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

And /etc/paths has the following content

/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
/Applications/eclipse/apache-maven-3.0.5/bin

I did try to look at this link as well but it didn't help much either

share|improve this question
2  
I'm not sure why your bashrc exports PATH three times, but a sub issue you have is that the third export makes the first two useless; it includes both dirs they add, and it forgets to have the :$PATH, removing the previous contents. –  demure Jun 4 '13 at 2:08
    
Could you suggest how I should modify the files, so as to correct the problem? N00b here. –  KodeSeeker Jun 4 '13 at 2:09
    
You can edit it with your editor of choice. vim, emacs, etc. Or, as you are on mac, if you want a gui editor: open -a TextEdit ~/.bashrc –  demure Jun 4 '13 at 2:12
    
And what contents do I put in bashrc?I dont think I have that file as of now.. –  KodeSeeker Jun 4 '13 at 2:21

3 Answers 3

up vote 3 down vote accepted

It seems like your shell is sh. OS X's /bin/sh is a version of bash where the main difference is that POSIX mode is enabled by default. It doesn't read ~/.bash_profile for login shells either. From man bash:

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. When invoked as an interactive login shell, or a non-interactive shell with the --login option, it first attempts to read and execute commands from /etc/profile and ~/.profile, in that order.

So you could use ~/.profile instead of ~/.bash_profile, but you'll probably just want to change the shell to a normal bash:

  • Set Startup > "Shells open with" to "Default login shell" if it's set to something else
  • Run chsh -s /bin/bash if the default login shell was changed

Notes about the comment thread in David X's answer:

  • Symlinking /bin/bash to /bin/sh wouldn't help. The /bin/bash and /bin/sh binaries are almost identical, but the behavior depends on the name bash was invoked with.
  • Terminal and iTerm open new shells as login shells by default, so for example bash reads ~/.bash_profile but not ~/.bashrc.
  • Normal user accounts are not included in /etc/passwd on OS X.
share|improve this answer
    
This sounds pretty much right, +1. –  David X Jun 4 '13 at 15:17
    
Works great! :) –  KodeSeeker Jun 4 '13 at 16:00

I'm fairly sure PATH needs to be set in .bashrc instead of .*profile.
Try putting this in your .bash_profile (replacing the export PATH lines):

if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
fi

and this in your .bashrc:

export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
share|improve this answer
    
Did you mix them both ? –  KodeSeeker Jun 4 '13 at 2:17
    
Did you mean the first snippet goes into .bashrc (which I dont have at the moment) and the second one in .bash_profile ? –  KodeSeeker Jun 4 '13 at 2:23
    
.bash_profile is run when bash starts as a login shell. (You probably don't do that, but it's a good idea to make sure it works anyway.) .bashrc is run when bash starts as a non-login shell, for example when you start a GUI terminal emulator (aka a xterm). –  David X Jun 4 '13 at 2:26
    
@KodeSeeker, no the first snippet goes in .bash_profile and the second goes in .bashrc. I'll edit to make that more clear. –  David X Jun 4 '13 at 2:27
    
Sadly it does not work .here are the contents of my .bashrc- pastebin.com/jiQ9i5q0 and my .bash_profile-pastebin.com/jPu1DfYm –  KodeSeeker Jun 4 '13 at 3:31

just have a single entry there ..... the third one over writes everything ...

export PATH=.:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:$PATH
share|improve this answer
    
Doesnt work . I still get sudo command not found when I start a new terminal –  KodeSeeker Jun 4 '13 at 2:17
3  
It's a bad idea to put . in your PATH, and it's a really bad idea to put it at the start. Doing so allows any directory with a executable file named sudo to potentially take over your computer (eg that that tarball you just downloaded). It also causes less severe problems with other commands that don't expect to type your password into. –  David X Jun 4 '13 at 2:20
    
@KodeSeeker, case in point. –  David X Jun 4 '13 at 2:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.