Zirek
Zirek

Reputation: 523

Mac OS terminal doesn't find commands

I have weird problem as all of the sudden terminal stopped reading any commands. Last weekend I installed Wordpress with PHP and mySQL and since that moment didn't have time to do anything more on laptop. Now I wanted to launch some react-native code but command wasn't found, then I tried different things to use some other commands and each time I get message

MBP-Mateusz-2:business-cards-native mateusz$ code .

-bash: code: command not found

and doesn't matter what command is that except standard ones like ls, cd etc. However when I try to write npm --version, or node --version, or launch visual studio code like before with code ., each time I get command not found. Doesn't anyone have issue like that? How to fix it as I'm super confused and have no idea even where to start.

Upvotes: 1

Views: 6262

Answers (1)

Marc Sances
Marc Sances

Reputation: 2614

You probably messed up your PATH environment variable, and now your computer cannot find the commands if you don't tell it directly where. The PATH variable contains the directories where the system should look for binaries if they're not in the current directory. If it gets corrupted for some reason, you won't be able to run any program from the terminal unless you pointed directly its location.

I would first run this command:

echo $PATH

so you can see which is the content of the PATH.

If it seems empty, or some critical folders are missing, try to add them temporarily:

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

Then try to run the commands again from the same terminal and see if that worked.

If that works, check if you have a ~/Library/LaunchAgents/environment.plist file and its content. It is possible that there is a key for the PATH and that its values are pointing something of your Wordpress stack but not the system directories.

If that looks fine, look at the ~/.bash_profile file. Find any export PATH instruction that may explain your issues. If you can't find any, but still exporting the PATH worked out, add at the end of the file that instruction as a workaround for fixing the mess:

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

(notice that I'm ading $PATH in this last case so if there is any other path actually configured it is added as well)

Good luck.


EDIT: That's the usual issue people has, but now that I've read your comments, the issue seems a bit more serious. It looks like the mySQL setup destroyed your /usr/local/ folder, which means you lost all the binaries located there npm, code, etc.

  • If you have a backup of the whole filesystem (which by experience is unlikely), restore /usr/local folder.
  • If you don't have any backups, you can reconstruct /usr/local... by reinstalling the software that cannot be found. Reinstall npm, VSCode, etc, that will place their executables again in the /usr/local folders and from there you'll be good to go. Install brew (since it's likely that also got deleted) then try brew install node and see if now you can run npm. If that works out, I'm afraid you'll have to reinstall all the software you lost again.

Upvotes: 4

Related Questions