A Comprehensive Guide to Installing npm on Mac

A Comprehensive Guide to Installing npm on Mac

NPM is an extremely important Node.js package manager that allows users to easily install, update, and uninstall any desired Node.js package. This article will provide a comprehensive guide to NPM installation for Mac users.

1. Preparation

Before installing NPM, we need to make sure we have installed the following software:

1. Node.js : NPM is released with Node.js. If Node.js is not installed, you can download it from the Node.js official website .

2. Xcode command line tool : You can download and install the Xcode command line tool here .

3. Homebrew : It is a package manager under Mac OS X, and detailed installation instructions can be found on the Homebrew official website .

After the installation is complete, you can run the following command to check whether the software was successfully installed:

$ node -v
$ npm -v
$ brew -v

If the version information is successfully output, it indicates that the software has been successfully installed.

2. Install NPM

There are various ways to install NPM on Mac, a few examples:

1. Install through NVM manager

To install the NVM manager, refer to the installation instructions on the NVM official website . Once installed, you can run the following command:

$ nvm install --lts

This command will install the latest LTS release.

2. Install through the official Node.js installer

You can download the .pkg file for Mac from the Node.js official website , and install it according to the prompts. After the installation is complete, NPM has been installed along with Node.js.

3. Install via Homebrew

NPM can be installed in Terminal with the following command:

$ brew install node

3. Update NPM

In order to get the latest packages and fix possible bugs and vulnerabilities, npm needs to be updated regularly. Here are three ways to update npm:

1. Update itself through npm

npm can be updated with the following command:

$ npm install -g npm

2. Update via Homebrew

npm can be updated with the following command:

$ brew update
$ brew upgrade node

3. Update via NVM (only for users who use NVM installation)

npm can be updated with the following command:

$ nvm install node --reinstall-packages-from=node

4. Uninstall NPM

Sometimes you need to uninstall npm, you can use the following command:

$ brew uninstall node
$ npm uninstall npm -g
$ sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}

Use these commands to completely remove npm from your Mac.

V. Summary

In this article, we introduced several ways to install, update and uninstall NPM on Mac, mainly including:

  1. Preparation
  2. install npm
  3. update npm
  4. uninstall npm

Depending on your needs, you can choose the method that suits you to work on. How to completely uninstall node and npm on Mac Develop Paper

Guess you like

Origin blog.csdn.net/m0_60437766/article/details/132116277