简体   繁体   中英

zsh: command not found on MacOS Monterey

I wanted to create a react project and when I executed the command it said zsh: command not found: npx Then I tried the ls command and it said zsh: command not found: ls .

After setting the export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" command both the ls and npx create-react-app command worked fine and when close the terminal and reopen again, the same command not found error shows. Is there any permenent fix without setting export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" command

For adding the variables to the path you need to add it to zshrc file for making that variable available locally.

The way you have used will only work until you use it in the same terminal window path only.

To solve the problem, follow these steps:

  1. Goto you home directory

  2. Simultaneously press cmd + shift + (.) Note:the last key is the key of dot

  3. On following step 2, new hidden files will appear in home directory, look for (.zshrc) file and open it using any text editor.

  4. Add your path variable in it, save and then close it.

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

  1. Open terminal and run the command: "echo $PATH" and see if your added variable is present in the output shown by terminal.

  2. If yes, You are now ready to go to use it from anywhere in terminal now.

In NVM repository shows how to add source lines to correct profile file:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

Source: nvm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM