How to Install Node.js on Mac OS [ 2 Steps]

In this article, We are going to perform Download Node.js package for Mac OS, Install Node.js on mac OS using Macintosh Installer, Install Node.js on macOS using Home brew, Installing Node.js and NPM using NVM on Mac OS, Uninstall/Remove Node.js and NPM from MacOS.

Introduction

Node.js is free and an open-source cross-platform JavaScript run-time environment that allows server-side execution of JavaScript code. It is used in developing web and networking applications

NPM(Node Package Manager) is command line tool for Node.js packages that installs, updates and uninstall packages in your projects.We don’t have install npm separately it is includes with Node.js installation.

Prerequisite

  • Mac OS with Terminal or Home brew Access

Download Node.js package for Mac OS

First download the latest node.js package from node.js official site and click on macOS installer, it will download .pkg file.

Install Node.js on mac OS using Macintosh Installer

once download completed, click on .pkg setup , you can see below options.

Introduction -> Click on continue

License -> select continue -> select Agree option

Destination Select -> select destination -> click on continue

Installation Type -> Select Install -> It will prompt for authentication -> click on Install Software

Summary -> click on close

once installation is completed, open the terminal by pressing command + space , open the terminal

To check node.js verios on mac OS

node -v

We have covered How to Install Node.js on macOS using macOS Installer.

Install Node.js on macOS using Home brew

If you want to install node.js on macOS using home brew follow the below commands

update the home brew package manager

brew update

Install node.js on macOS using home brew

brew install node

To check node.js version on macOS

node -v

To check npm version on macOS

npm -v

To update node.js package on macOS

brew update
brew install node

To upgrade the node.js package using home brew on macOS

brew upgrade node

To uninstall the node.js package using home brew on macOS

brew uninstall node

We have covered How to Install Node.js on macOS using Home brew.

Installing Node.js and NPM using NVM on Mac OS

Download the NVM installation script from NVM GitHUB Page using curl.

curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh -o install_nvm.sh

To download and install node.js script using wget

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

once downloaded, run the bash script

bash install_nvm.sh

It will install your system’s home directory ~/.nvm  and adds configuration in ~/.profileLoad the profile

source ~/.profile

OR

source ~/.bashrc

if NVM packages not added in your profile , To add manually in your profile, open .profile or .bashrc , add below lines into it.

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

To check all available node.js versions

nvm ls-remote

Sample output:

.....
v12.14.0 (LTS: Erbium)
v12.14.1 (LTS: Erbium)
v12.15.0 (LTS: Erbium)
v12.16.0 (LTS: Erbium)
v12.16.1 (LTS: Erbium)
v12.16.2 (LTS: Erbium)
v12.16.3 (LTS: Erbium)
v12.17.0 (LTS: Erbium)
v12.18.0 (LTS: Erbium)
v12.18.1 (LTS: Erbium)
v12.18.2 (LTS: Erbium)
v12.18.3 (Latest LTS: Erbium)
v13.0.0
v13.0.1
v13.1.0
v13.2.0
v13.3.0
v13.4.0
v13.5.0
v13.6.0
v13.7.0
v13.8.0
v13.9.0
v13.10.0
v13.10.1
v13.11.0
v13.12.0
v13.13.0
v13.14.0
v14.0.0
v14.1.0
v14.2.0
v14.3.0
v14.4.0
v14.5.0
v14.6.0
v14.7.0
v14.8.0
v14.9.0
v14.10.0
v14.10.1

Error: npm update check failed try running with sudo or get access change the permission to install node.js

sudo chown -R $USER:$(id -gn $USER) /home/ubuntu/.config

Now you can install node.js version as you want.

nvm install 12.18.3

To set recently node.js version

nvm use 12.18.3

To verify the nvm is installed

command -v nvm

check the node varsion

node -v

check the nvm version

nvm --version

To list npm modules locally and global

npm list
npm list -g 

We have performed ,How to Install Node.js on macOS using NVM manager.

To install coffee-script and grunt cli on macOS

npm install -g coffee-script
npm install -g grunt-cli

Error: nvm node version not found in vim shell

sudo chmod ugo-x /usr/libexec/path_helper

Uninstall/Remove Node.js and NPM from MacOS

To uninstall nvm from macOS manually, remove the nvm directory

rm -rf "$NVM_DIR"

open the ~/.bashrc file and remove below lines

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[[ -r $NVM_DIR/bash_completion ]] && \. $NVM_DIR/bash_completion

Conclusion

We have covered Download Node.js package for Mac OS, Install Node.js on mac OS using Macintosh Installer, Install Node.js on macOS using Home brew, Installing Node.js and NPM using NVM on Mac OS, Uninstall/Remove Node.js and NPM from MacOS.

Related Articles

How to Install Node.js and NPM on Ubuntu 20.04 LTS

How to Install Latest Node.js and NPM on Ubuntu 19.04,18.04/16.04 LTS

How to Install Node.js on Windows 10

iOS Architecture, concepts and Xcode Installation

FOSS TechNix

FOSS TechNix (Free,Open Source Software's and Technology Nix*) founded in 2019 is a community platform where you can find How-to Guides, articles for DevOps Tools,Linux and Databases.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link