Terminal 'bash: command not found' for most commands [duplicate]
I'm really new to Mac OSX and UNIX based systems. I wanted to run a few Windows games on my Mac Mini so I started installing Wine and MacPorts.
I think the installs are correct, but when I type sudo port install wine
I see a not found error in my terminal. I tried other basic commands like say
and clear
and all of them return the same not found error.
My research shows that my PATH might be incorrectly set, but it lacks steps I can implement.
Specifically, I ran this command: echo $PATH
and it returned:
/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin
I'm a complete newbie to mac and have no idea where .bash_profile or any of those files are. My skills let me install Xcode and the Command Line tools for Xcode and I sense I need to level up on path management.
At this point I need help managing my dot files and changing my path to fix these specific errors on Mountain Lion.
What are my next steps?
Solution 1:
$PATH should contain these folders: /usr/bin:/usr/sbin:/bin:/sbin
.
Try editing ~/.bash_profile
, ~/.profile
, or ~/.bash_login
(with for example /usr/bin/open ~/.bash_profile -a TextEdit
) and commenting out any lines that modify the path.
If that works, you can add a line like export PATH=/opt/local/bin:/opt/local/sbin:$PATH
to ~/.bash_profile
.
Solution 2:
Similar problem was happening to me, so what I did was:
1) typing export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
into the terminal in order to make it temporarily working
2) Editing bash_profile by typing /usr/bin/open ~/.bash_profile -a TextEdit
3) When I opened my bash_profile file I realised the last line export looked really messy with some strange symbols, so I changed it entirely to export PATH=/opt/local/bin:/opt/local/sbin:$PATH
I'm an absolutely beginner at this but I managed to get those steps by reading pieces of solutions from different questions on SE, so hope it could help someone else.
Solution 3:
It sounds like you overwrote your path rather then just adding to it.
Make sure when you set your PATH you include "${PATH}"
to include your existing path, as well.
By default the $PATH is set in a couple of files. Technically you should add to your $PATH in the .bash_profile file in your home directory.
One suggestion if to check if a certain folder exists before you add them to your PATH.
For example I have:
if [ -d /usr/local/bin ] ; then
PATH=/usr/local/bin:"${PATH}"
fi
if [ -d /usr/local/mysql/bin ] ; then
PATH=/usr/local/mysql/bin:"${PATH}"
fi
if [ -d /opt/local/bin ] ; then
PATH=/opt/local/bin:"${PATH}"
fi
if [ -d /opt/local/sbin ] ; then
PATH=/opt/local/sbin:"${PATH}"
fi
if [ -d ~/bin ] ; then
PATH=~/bin:"${PATH}"
fi
(The -d directory
command checks to see if the directory exists)
Solution 4:
For me I got into this exact issue when I attempted to add a new directory to PATH using an incorrect export command in my ~/.bash_profile
. Both examples below.
export PATH=/some/new/path:PATH (incorrect, note missing $)
vs
export PATH=/some/new/path:$PATH (correct)
Solution 5:
In addition to the fix it answers, I'd also like to call out one thing to test.
If your current window simply has a bad PATH variable and your system isn't more broken, you can fix the path easily:
echo $PATH
/usr/libexec/path_helper
Compare the output of the two above commands. If you want to return to a "safe" path, just copy and paste the line that the path_helper
provides into that terminal. On an unmodified Mac 10.11 system, you should have this output from the helper tool:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"; export PATH;
If your path needs to be customized, then look to the excellent answers also on this question.