npm command not found - Mac

Page content

How to Install npm Command on Mac

If you are encountering the “npm command not found” error on your Mac, don’t worry. This tutorial will guide you through the process of installing npm on your Mac.

Why npm is not included by default on Mac

Unlike Linux distributions, macOS does not come with Node.js and npm pre-installed. Therefore, when you try to use the npm command on a Mac without having Node.js and npm set up, you will get the “npm command not found” error.

Installation Steps

To install npm on your Mac, follow these steps:

  1. Install Homebrew (if you haven’t already):

    • Homebrew is a package manager for macOS that makes it easy to install and manage software packages. If you don’t have Homebrew installed, you can do so by running the following command in your terminal:
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
      
  2. Install Node.js and npm using Homebrew:

    • Once you have Homebrew installed, you can use it to install Node.js and npm by running the following command in your terminal:
      brew install node
      
  3. Verify npm installation:

    • After the installation is complete, you can verify that npm is installed by running:
      npm -v
      
  4. Update npm (optional):

    • You can also update npm to the latest version by running:
      npm install npm@latest -g
      

Conclusion

By following these steps, you should now have npm successfully installed on your Mac, and you should no longer encounter the “npm command not found” error. npm is a powerful package manager for JavaScript that allows you to easily manage dependencies and packages for your projects. Happy coding!