30

I installed the most recent update to OS X Lion (10.7). After I did that, my terminal won't recognize normal commands. I typed ls and got:

-bash: ls: command not found

I figured I'd try to add usr/bin to my path, but I can't find .bash_profile to edit it since typing edit .bash_profile won't work. I can't set the Finder to show all files since my terminal won't recognize the commands necessary to do that.

what do I need to do?

  • 2
    Let's get a path and see what shakes out. export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin paste the dark part (or type it VERY CAREFULLY) - since two commands are missing - something whacked your path. Before doing anything big, kicking off a backup might be prudent. – bmike Aug 23 '11 at 1:27
  • 1
    @bmike thanks! added that to .bash_profile and it's all working now. had to open .bash_profile like this: /usr/bin/vi ~/.bash_profile Put that as an answer and I can accept! – LuxuryMode Aug 23 '11 at 1:37
41

Since two commands are missing something “stomped” your path.

Before doing anything big, kicking off a backup might be prudent.

The default path on Mac OS X 10.7 (Lion) is something like this:

PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

If you reset the path by typing the above into a shell window, and then typing export PATH it should fix that one window.

So you can start there and see what else might be amiss and fix it in your startup dot files or elsewhere it gets defined.

This breakage is almost always something you need to fix in your dot files. For bash, edit and fix .bash_profile and/or .bashrc by undoing a recent change it just setting the $PATH you need again. The usual error is assigning a new path and not referring to the previous value of the variable on the right hand side of the =

  • 2
    For me, this provides a temporary fix. – Etienne Low-Décarie Jun 26 '14 at 12:59
  • 2
    Thank you! I puckered up for a bit when ls didn't work after updating .bash_profile 😂 – Adrian Sep 16 '18 at 2:34
  • Yeah @Adrian a syntax error or empty PATH can cause intense anxiety 😅🤭🤬🔥 – bmike Sep 16 '18 at 2:38
  • This gave a temporary fix. I had to redo all the steps once I restart the CMD – Pawan Nov 15 '18 at 17:25
  • This still works for Mac OS 10.14.3 – Stephen Romero Sep 2 at 20:39
10

This should fix the problem completely and permanently.

first, export environment paths by using below command in the terminal.

export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/b‌​in

now you have the commands you want. (eg. try ls. You'll see the command is working). But this is only for the current session. If you close the terminal and open a new one, you will have the previous issue. To make this change permanent, use below command,

go to home directory

cd ~

open .bash_profile file in nano / vim (I'm using nano here)

nano .bash_profile

This will open up nano editor. In a new line, paste the following;

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

press 'control'+'o' to save (WriteOut) and 'control'+'x' to exit nano.

All done ! Now try the commands.

3

It sounds to me as if /etc/profile wasn't run at shell startup. It's the global startup file responsible for initializing PATH. Check whether /etc/profile exists and is readable and executable with the following command:

. /etc/profile

If it isn't there, you'll need to restore it from a backup or another machine with Lion installed, or install Lion again. If it exists but isn't executable, try using Disk Utility to Repair Disk Permissions.

If it does exist and is executable (and it contains some code), either it may not be getting run when it's supposed to or your startup script may somehow be overriding it. As a workaround, try putting . /etc/profile at the start of your ~/.bash_profile to ensure it is run. If you still encounter the problem, add echo $PATH after running it to see if PATH was initialized properly. If it was, something in your script is changing it.

Here's the default contents of /etc/profile:

# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
fi

path_helper constructs the default PATH. You could try running

unset PATH; /usr/libexec/path_helper -s

to see what it produces.

In any case, if the problem isn't in your startup script(s), please contact Apple support http://www.apple.com/support/contact/ or report a bug at https://bugreport.apple.com/ to let Apple know there's a problem.

  • unset PATH; /usr/libexec/path_helper -s shows me PATH that is not contained in my /etc/profile. Any suggestions? – Etienne Low-Décarie Jun 26 '14 at 13:00
  • Running . /etc/profile temporarily fixes the problem. I have pasted into the top of my ~/.bash_profile, but it appears that this is not run either. – Etienne Low-Décarie Jun 26 '14 at 13:10
  • 1
    Check the bash man page for the complete list of startup files and the order in which they are searched. If you have a login file it takes precedence over the profile, for example. Check for other startup files. – Chris Page Jun 26 '14 at 19:01
1

To check that it is indeed a problem with your path, what's the result of /bin/ls ?

If it works, than you should restore your path to /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin, you can use for example VI whose path is (on my mac) /usr/bin/vi.

0

I thought of sharing the mistake that led me to this error - at least in my case,

When I added a new PATH in ~/.bash_profile, I forgot to add :$PATH at the end of the path that I just added.

I used the temporary fix ( the following command in the terminal) that masters here have already pointed out to get back to bash_profile since I could not use vi commands to open it in the first place.

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

Once I got in, I rectified my mistake.

(Negative data matters!)

New contributor
AshlinJP is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
-1

I was trying to set my maven path to envoronment variables when this happened. So I just moved my .profile and .bash_profile file to trash and tried again and it worked.

-1

Resetting your terminal will work. It will reset your basic configurations.

Reset your terminal. From top navigation go to Shell >> Reset.

enter image description here

  • 1
    How does resetting the Terminal resolve an issue with bash? – nohillside May 4 '18 at 10:16
-2

Looks like your PATH variable is corrupt. Check if by any chance you are modifying the PATH variable within your script or simply check the PATH by saying echo $PATH and you can make sure if nothing is corrupt.

-3

you can export the path as follows:

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

  • 3
    Welcome to Ask Different! This question already has an accepted answer and your answer is not materially different than the accepted answer. Please see the following FAQ on how to provide a good answer: apple.stackexchange.com/help/how-to-answer – fsb Apr 29 '16 at 17:39

You must log in to answer this question.

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