7

Getting the error:
-bash: sudo: command not found
echo $PATH outputs PATH:EC2_HOME/bin
I'm running Mac OSX 10.8.3

That seems wrong even for a n00b like me. How do I fix my $PATH and return my computer to it's former self?

4 Answers 4

14

As stated in the comments the right files to set up your $PATH variable are: ~/.profile or ~/.bash_profile

export PATH=/usr/bin:/usr/sbin:/bin:/usr/local/bin:/sbin:/opt/x11/bin:$PATH

In this way when you re-enter in the console your PATH will work fine. You can add other directories to your $PATH as you like.

If you just copy and past that line in an active console you just set the PATH variable temporary, when you logout and login again you will loose your path, so add it in your ~/.bashrc file.

Sign up to request clarification or add additional context in comments.

5 Comments

The trailing slashes are unnecessary. Note that this will lengthen your $PATH for each new shell, which is mostly harmless but annoying.
Removed the unnecessary trailing slashes
The .bashrc is notionally the wrong place to do this, ideally you should use ~/.profile ~/.bash_profile or ~/.bash_login (depending on however you're set up) so that potentially expensive environment setup only has to be run once, then inherited by all the subshells running ~/.bashrc. And the login shell doesn't run .bashrc anyway unless ~/.bash_login or ~/.bash_profile is set up to do it.
Thanks @KeithThompson and @Alex North-Keys, I've edited my answer, I've switched to zsh from to much time :-)
where can open ~/.profile or ~/.bash_profile without terminal?
1

I'm not sure how you've managed to get into that state, though this article explains how you can set your path.

If it helps, the output from my echo $PATH is: -

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin

2 Comments

I hope the first element is /usr/bin, not usr/bin.
@KeithThompson, you're absolutely right and thanks for spotting the error of my copy and paste. I've corrected the answer ;O)
1
  1. go to shell
  2. choose new command
  3. put this : sudo vim .bash_profile
  4. then put : export PATH=/usr/bin:/usr/sbin:/bin:/usr/local/bin:/sbin:/opt/x11/bin:$PATH

Comments

0

This worked for me:

echo $PATH

Followed by:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.