'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



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1