Can't use terminal, I keep getting "zsh: command not found" even after an OS re-install

I don't remember what I had done, but every time I attempt to run a command in terminal, it returns a "zsh: command not found"


I performed a clean install of OSX (Sonoma 14.4) and the problem

still persists. So I am convinced this is default behavior and not user

error.

MacBook Pro 15″, macOS 14.4

Posted on Mar 21, 2024 12:32 PM

Reply
Question marked as Top-ranking reply

Posted on Mar 21, 2024 12:40 PM

When you switch the shell from Bash to Zsh, the latter shell has no default dot file to obtain its PATH, so any UNIX command you run from the Terminal will state it cannot be found until you rectify a PATH solution.


Do you have a ~/.zshrc file in your home directory by opening a Finder window and pressing shift+cmd+. to toggle hidden dot files? Scroll down in that Finder window until you encounter the grayed out .zshrc file and then single-click on it and hit the space bar to display it with Finder's Quick Look. If the file exists, is there a PATH statement in it? If it does not exist. copy and paste the following in the Terminal, then press return.


<<"EOF" > ~/.zshrc
export PATH=".:/usr/local/bin:${PATH}"
PS1="%m: %~ %% "
EOF


That will write a .zshrc file in your home directory with PATH and PS1 shell prompt set. Then run this command:


source ~/.zshrc


and now, your current Terminal window knows your PATH, and UNIX commands should work now as they can be found.

7 replies
Question marked as Top-ranking reply

Mar 21, 2024 12:40 PM in response to hoverbored

When you switch the shell from Bash to Zsh, the latter shell has no default dot file to obtain its PATH, so any UNIX command you run from the Terminal will state it cannot be found until you rectify a PATH solution.


Do you have a ~/.zshrc file in your home directory by opening a Finder window and pressing shift+cmd+. to toggle hidden dot files? Scroll down in that Finder window until you encounter the grayed out .zshrc file and then single-click on it and hit the space bar to display it with Finder's Quick Look. If the file exists, is there a PATH statement in it? If it does not exist. copy and paste the following in the Terminal, then press return.


<<"EOF" > ~/.zshrc
export PATH=".:/usr/local/bin:${PATH}"
PS1="%m: %~ %% "
EOF


That will write a .zshrc file in your home directory with PATH and PS1 shell prompt set. Then run this command:


source ~/.zshrc


and now, your current Terminal window knows your PATH, and UNIX commands should work now as they can be found.

Mar 21, 2024 1:48 PM in response to hoverbored

You need to revisit the npm site and installation/supported operating system guidelines. If it was installed by homebrew, you need to review any messages issued by homebrew about the npm installation progress. Neither npm or homebrew are Apple product or services and resolution rests with them.


At the Zsh shell, see if this command returns any results:


which -a npm


Mar 21, 2024 4:21 PM in response to hoverbored

npm is not part of the operating system. You've installed one or more 3rd party system modifications. The most likely candidate is the notorious "homebrew" package. Your results are typical.


You will need to completely reset the computer and reinstall the operating system. Do not restore any files from backup. I recommend learning how all these tools work behind the scenes before diving into the deep end again.

Mar 23, 2024 12:56 PM in response to hoverbored

Hello Author! I also had the same issue that happened 2 to 3 days ago and ever since have been trying to resolve it. Steps I have taken to resolve: Update my Mac system, clean re-install of OSX ( Sonoma 14.4), update the PATH in my nano editor, reinstall VS Studio Code, and update. I keep getting the statement "zsh: command not found" in my terminal. I also would love to know how to solve this.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Can't use terminal, I keep getting "zsh: command not found" even after an OS re-install

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.