4

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?

  • What does /usr/bin/tail ~/.bash_profile return? – nohillside Apr 17 '14 at 16:06
  • @patrix It returns this: export PATH=/usr/local/bin:$PATH export PATH=/usr/local/bin:$PATH – Howard Stark Apr 17 '14 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 '14 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 '14 at 17:04
9

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

  • 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 '14 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 '14 at 16:58
6

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

  • 1
    This is the correct answer. The part of bmike’s answer that fixed the problem was starting a new terminal session, not removing a duplicate line from .bash_profile. – samh Dec 31 '18 at 14:08
1

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.

0

The correct environment configuration in .bash_profile file should be like this:

export PATH="/usr/local/bin:$PATH"

and not:

export PATH='/usr/local/bin:$PATH'

see this:

So the correct step to config the brew environment variable on your Mac is as follows:

  1. The correct command is:

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

  2. Now we need to activate your changes. Type this command to activate:

    source .bash_profile

    Or you can use this command to open the file:

    /usr/bin/open ~/.bash_profile

    and then fix it to the correct text and then save and quit, the path should use " ".

  3. Don't forget to activate your changes also. Still this command:

    source .bash_profile

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .