zsh: command not found: npm

zsh: command not found: npm

How to solve zsh: command not found: npm issue

If you receive the error "zsh: command not found: npm", the npm command is unavailable on your system. This can happen if you do not have Node.js and npm installed on your computer or are not added to your system's PATH environment variable.

You must install Node.js and npm on your system to fix this error. You can download the latest version of Node.js from the official website (https://nodejs.org/en/) and follow the installation instructions. Once Node.js is installed, you can use the npm command to install and manage npm packages.

Alternatively, you can try adding the path to the npm command to your PATH environment variable. This will allow you to run the npm command from any directory on your system. To do this, you will need to open the .zshrc file in a text editor and add the path to the npm command to the PATH variable.

For example, if the npm command is located at /usr/local/bin/npm, you would add the following line to your .zshrc file:

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

Once you have added this line to your .zshrc file, save the file and run the source ~/.zshrc command to apply the changes. You should now be able to run the npm command without any errors.

It's worth noting that the specific steps to fix this error may vary depending on your system and configuration. Suppose you are still having trouble getting the npm command to work. In that case, you may want to consult the official Node.js and npm documentation or seek help from experienced users on online forums or communities.

Install Node.js

To install Node.js on your computer, you must download the appropriate installer for your operating system from the official Node.js website (https://nodejs.org/en/). The Node.js website provides installers for all major operating systems, including Windows, MacOS, and Linux.

Once you have downloaded the installer, follow the steps below to install Node.js on your system:

MacOS

  1. Double-click the .pkg file you downloaded to start the installation process.

  2. Follow the on-screen instructions to complete the installation process.

  3. Once the installation is complete, you can verify that Node.js is installed by running the node -v command in a terminal window. This should print the version number of Node.js installed on your system.

Linux

  1. Open a terminal window and navigate to the directory where you downloaded the Node.js installer.

  2. Use the tar command to extract the contents of the .tar.gz file you downloaded. For example:

Copy codetar -xzvf node-v12.16.2-linux-x64.tar.gz
  1. Use the cd command to navigate to the directory created when you extracted the .tar.gz file. This directory will have a name similar to node-v12.16.2-linux-x64.

  2. Use the sudo command to copy the extracted files to the /usr/local directory. This will allow Node.js to be used by all users on the system:

Copy codesudo cp -r * /usr/local
  1. Once the files have been copied, you can verify that Node.js is installed by running the node -v command in a terminal window. This should print the version number of Node.js installed on your system.

Windows

  1. Double-click the .msi file you downloaded to start the installation process.

  2. Follow the on-screen instructions to complete the installation process.

  3. Once the installation is complete, you can verify that Node.js is installed by opening a command prompt and running the node -v command. This should print the version number of Node.js installed on your system.

It's worth noting that the specific steps to install Node.js on your system may vary depending on your operating system and configuration. If you encounter problems during installation, you may want to consult the official Node.js documentation or seek help from experienced users on online forums or communities.

Related articles

Ruslan Osipov
Written by author: Ruslan Osipov