The zsh: command not found: nodemon error occurs when the “nodemon command is unavailable in your zsh shell’s PATH or nodemon is not installed in your system.”
The nodemon is a utility that monitors for changes in your Node.js application and automatically restarts the server.
Common reasons for the error
- Nodemon is not installed in your system.
- Nodemon is available in a different path.
- Nodemon utility is not installed globally.
How to fix the command not found: nodemon error
Here are some solutions to fix the command not found: nodemon error.
- Check if a nodemon is installed.
- Install nodemon; if not installed.
- Check the path.
- Add npm’s global bin directory to PATH.
- Local installation.
Solution 1: Check if nodemon is installed
You can use the following command to check if nodemon is installed globally:
npm list -g --depth=0 | grep nodemon
Solution 2: Install nodemon; if not installed
If nodemon is not installed, you can install it globally using:
npm install -g nodemon
How to install nodemon in Ubuntu or Mac OS correctly
Run the npm command to install nodemon globally in the system path.
sudo npm install -g nodemon
How to install nodemon in Windows correctly
Run the following command to install nodemon globally in Windows 10.
C:\> npm install -g nodemon
Solution 3: Check the PATH
After installing, if you’re still facing the issue, it’s possible that the directory where global npm packages are installed is not in your shell’s PATH. You can check your PATH using:
Solution 4: Add npm’s global bin directory to PATH
If the directory where nodemon is installed is not in the PATH, you can add it. Usually, global npm packages are installed in ~/.npm-global/bin or /usr/local/bin.
You can add it to the PATH by adding the following lines to your ~/.zshrc file:
After adding, reload the .zshrc file using:
Solution 5: Local Installation
If you’ve installed nodemon locally in your project (i.e., as a dev dependency), you won’t be able to run it directly from the command line unless you use npx or specify the full path to the nodemon binary in the node_modules directory.
To run a locally installed nodemon, you can use:
I hope one of these solutions works for you!