Install npm on Mac | Easiest Way Possible

Start from the beginning
                                        

As a final result, you will see a snippet below.

Step 3: Now, validate that the NodeJS and NPM are installed on your system

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

Step 3: Now, validate that the NodeJS and NPM are installed on your system. To do so, open the command line and run the below command. It will return the installed version number.


Command: node -v


Step 4: However, if a newer version is available, you can update yours by executing the following command in CLI. It will update the NPM and NodeJS versions simultaneously.


Command: $ sudo npm install npm –global // Update the npm CLI client


Step 5: Once you have the required NPM version installed, configure the NODE HOME variable. By utilizing the same CLI, run one more command.


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


However, if you have different profiles and want to set variables for all users. Then, you should use the two CLI commands listed below to add configuration to the ".bash_profile" file.


Command: echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile Command: source ~/.bashrc


Method 2: Install NPM Mac Version with Homebrew

Homebrew is one of the most used and reliable package managers MacOS professionals consider. It helps to install and use the stuff that a user needs.


The main reason for using Homebrew is that it doesn't interfere with system binaries and libraries. All the installations are made in a separate directory known as "/usr/local."


Further, to install Homebrew on your macOS system, run the command:/bin/bash -c "$(curl -fsSLhttps://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"


Following its installation, undergo the NPM installation process as listed.


Step 1: A single command is enough with Homebrew to download and initiate the NPM and NodeJS installation.


Open the CLI of the macOS machine and execute the command: brew install nodeNPM will be installed in a minimal amount of time.


Step 2: To verify the available version of NPM on your system, use the below commands.


To check the NPM version: npm -v


To check NodeJS version: node -v


Step 3: By default, Homebrew installs the latest version. However, if the latest version is not installed, use the following macOS CLI commands.


To update NPM: brew update


To update NodeJS: brew upgrade node


 Method 3: NVM Approach to Install NPM Mac

On a macOS system, you can use NVM or Node Version Manager to install NPM. The procedure is quite streamlined and completed using only the CLI.


Step 1: Download and install the NVM by using any of the following approaches.


Approach #1: Installation through cURL


curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash


Approach #2: Installation through wget

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash

Step 2: Run "nvm -version" to verify its installation on your system. The CLI will display the NVM version as the output.


In addition, it's recommended that the command be added to the .bash_profile or .zshrc file. It ensures that all configured terminals have the same configurations. To do so, use the below command.


Command: echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profileTo finalize the changes, run: source ~/.bashrc


Step 3: Run the MVM command to install the NodeJS and NPM.


Command: nvm install node


In addition, to install a specific NPM version, use the below command.


Command: nvm install v12.15.0


Here, "12.15.0" is the version number, which can be modified per requirements.


Step 4: To verify the NPM installation through NVM, utilize the command below.


Command: node -version


To list all node versions: nvm is


Concluding Up

Installing NPM on macOS is an easy and quick procedure. There are three main methods available to install NPM on a Mac machine. The first method is downloading the package and installing it through GUI. The second method is completed through the Homebrew package manager. The third method uses NVM. You can use any of the installation approaches, as their end result is quite similar, that is, you get the NPM and Node JS on your system.

The Original Blog Published at Positiwise: https://positiwise.com/blog/install-npm-on-mac

You've reached the end of published parts.

⏰ Last updated: Jul 15, 2024 ⏰

Add this story to your Library to get notified about new parts!

Install npm on Mac | Easiest Way PossibleWhere stories live. Discover now