This article will tell you how to install Node JS and NPM(node package manager) on MacOS step by step. There are three ways to install it on mac, run the official installer, install node binary for macOs directly or use mac Homebrew package manager. We will introduce them all.
1. Install Node JS Use Node Installer For Mac.
- Download node js mac installer (pkg file) from node js official site.
- Click the downloaded file to open installer. Process the installation as normal by click next or continue button. Please note where the node js is installed. It will be installed to /usr/local/bin/node directory. And the npm( node package manager ) will be installed to /usr/local/bin/npm directory.
- After installation, open a terminal in macos, run
npm -vin the terminal to verify the installation.
$ node -v v8.12.0 $ npm -v 6.4.1
- Uninstall node js in this way is just to delete node, node_modules folder under below global or your personal folders ( for example/usr/local/lib/node,/usr/local/lib/node_modules).
/usr/local/lib/, /usr/local/include/, /Users/$user_home_dorectory/lib/, /Users/$user_home_dorectory/local/include
2. Install Node JS Use MacOS Binary.
If you want to use multiple node js version in your mac. You can also download different version of node js zip file, then unzip and save them in different folder. Then you can use different version node js.
- Download node js MacOS version binary file.
- Unzip the zip file to a local folder, and cd into that folder in terminal. Then you can find the bin folder under it. The node and npm executable file are all saved in the bin folder.
$ cd /Users/zhaosong/Downloads/node-v8.12.0-darwin-x64
- Cd into the bin folder, and execute
./npm -vto verify node and npm version.
- If you want to use this node js version conveniently, you can add the bin folder full path ( /Users/zhaosong/Downloads/node-v8.12.0-darwin-x64/bin ) to os system environment variable $PATH. Please refer How To Set JAVA_HOME, MAVEN_HOME Environment Variable In MacOS to learn how to add node bin folder in MacOS $PATH value.
- After above step, you can run node command from any directory in terminal, you do not need to go to the node js bin folder to run it.
- Uninstall node js in this method is similar with section one in this article. You need to remove the unzip node js folder and related installed node modules.
3. Install Node JS Use MacOS Homebrew.
Homebrew is MacOS package manager tool. You can use it to install MacOS software ( such as node js ) easily.
brew -vin terminal to check whether homebrew is installed or not.
192:bin $ brew -v Homebrew 1.7.7 Homebrew/homebrew-core (git revision 2278; last commit 2018-10-17)
- If homebrew do not exist, then run below command in terminal to install it on your MacOS.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Then you can install node js use homebrew easily.
$ brew install node
- Upgrade homebrew command.
$ brew upgrade
- To upgrade node with homebrew.
$ brew upgrade node
- It is also very easy to uninstall node js with homebrew.
$ brew uninstall nod