Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I was trying to install homebrew, which wasn't working. It told me to do echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile. However this wasn't having any affect, and I thought maybe it was because of echo (I don't know any Bash), so I removed the Echo, ran brew doctor and it spat this out, which concerned me:

/usr/local/bin/brew: line 2: dirname: command not found
/usr/local/bin/brew: line 5: basename: command not found
/usr/local/bin/brew: line 8: readlink: command not found
/usr/local/bin/brew: line 16: cd: /Users/howard/../Library: No such file or directory
/usr/local/bin/brew: line 23: tr: command not found
/usr/local/bin/brew: line 23: uname: command not found
/usr/local/bin/brew: line 28: exec: ruby: not found

Is there any way to undo what I just did? Also, can someone please explain to me what I just did? I am never going to make the stupid mistake of copying and pasting commands I don't understand. I feel like a total moron right now.

I worry that I may have overriden /usr/bin/ with stuff? I can't run most of the basic commands like man, ls, and a few others. cd still works though. Is there any hope for me, or do I need to reinstall my OS?

share|improve this question
    
What does /usr/bin/tail ~/.bash_profile return? –  patrix Apr 17 at 16:06
    
@patrix It returns this: export PATH=/usr/local/bin:$PATH export PATH=/usr/local/bin:$PATH –  Howard Stark Apr 17 at 16:09
    
Also, to rule out that it's just your path messed up, /bin/ls and /usr/bin/man should still exist and work... –  bmike Apr 17 at 16:59
    
@bmike this fixed my problem! Thank you so much! I really appreciate it. I was freaking out for a bit there. –  Howard Stark Apr 17 at 17:04

3 Answers 3

up vote 4 down vote accepted

You certainly don't need to reinstall - just remove the offending last line of the file and restart terminal to see the effects.

If you don't know how to edit the file from terminal, you can open the file in your system's default plain text editor:

/usr/bin/open ~/.bash_profile

Just delete the last line and save the file. (The >> tacks the output of the echo on to the end of the file) At that point, quit terminal, reopen terminal and test brew doctor again.

Apple has an overview of editors you can use in terminal if you want to edit files more regularly.

For beginners, the nano editor is perhaps the easiest since it has visible help for basic commands. You can get some more guided help on nano from the web by opening the URL in your preferred browser (or having terminal do that for you open http://www.nano-editor.org/).

share|improve this answer
    
The issue is that it is a hidden file and I can't use anything like vi or nano or even the open command. I know about defaults, but even defaults returns command not found. I don't know what to do at this point. –  Howard Stark Apr 17 at 16:51
    
@HowardStark You are correct! I should have added the path to open - type /usr/bin/open ~/.bash_profile into terminal and press return. That should open TextEdit with the hidden file so you can see the contents / delete that last line. Also, /usr/bin/nano ~/.bash_profile would work. There needs to be one (or more) space before the ~ for the command to work. Since your path is messed up, I'll make the path to open explicit in the body of the answer as well. –  bmike Apr 17 at 16:58

You say that you ran the following command:

echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile

This would have appended the line export PATH='/usr/local/bin:$PATH' to your .bash_profile. However, you then ran the line without the echo.

This would have broken your path, but only for the session that you're in. The ">> ~/.bash_profile" would have had no effect since there is no output of that command.

Simply close the Terminal window and open a new one. Running export just changed the PATH for your current shell. A new shell will source the relevant files again for you, setting the path correctly, providing the line that you added to your profile with the echo is removed (see bmike's answer).

share|improve this answer

You didn't see any effect because you should have restarted terminal or alternatively

source ~/.bash_profile

To make the changes into effect. Addings paths into the .bash_profile file is sort of like adding shortcuts into the desktop, except these are shortcuts for the terminal, i.e. you tell it where stuff is.

share|improve this answer

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.