How To Install / Uninstall Node JS, NPM On Mac

This article will tell you how to install/uninstall Node JS and NPM(node package manager) on macOS step by step. There are three ways to install/uninstall it on macOS, run the official installer, install node binary for macOS directly, or use mac HomeBrew package manager. We will introduce them all.

1. Install / Uninstall Node.js Use Node Installer For macOS.

  1. Download Node.js mac installer (pkg file) from Node.js official site.
  2. Click the downloaded file to open the installer. Process the installation as normal by clicking the next or continue button. Please note where 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.
    install-node-js-for-macos-wizard
  3. After installation, open a terminal in macOS, run node -v and npm -v in the terminal to verify the installation.
    $ node -v
    v8.12.0
    $ npm -v
    6.4.1
    
  4. 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
  5. You can also run the below command which is provided by the node official website to uninstall Node.js completely.
    sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}

2. Install / Uninstall Node,js Use macOS Binary.

If you want to use multiple Node.js versions in your macOS. You can also download different versions of Node.js zip file, then unzip and save them in different folders. Then you can use different versions Node.js.

  1. Download node js MacOS version binary file.
  2. 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

    extracted-node-js-tool-files-folder

  3. Cd into the bin folder, and execute ./node -v and ./npm -v to verify node and npm version.
  4. 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 read the article How To Set JAVA_HOME, MAVEN_HOME Environment Variable In macOS to learn how to add node bin folder in macOS $PATH value.
  5. After the above step, you can run the node command from any directory in the terminal, you do not need to go to the node js bin folder to run it.
  6. Uninstall node js in this method is similar to section one in this article. You need to remove the unzip node js folder and related installed node modules.

3. Install / Uninstall Node.js Use macOS Homebrew.

Homebrew is a macOS package manager tool. You can use it to install macOS software ( such as Node.js ) easily.

  1. Run brew -v in 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)
    
  2. If homebrew does not exist, then run the below command in the terminal to install it on your macOS.
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  3. Then you can install node js use homebrew easily.
    $ brew install node
  4. Upgrade homebrew command.
    $ brew upgrade
  5. To upgrade node with homebrew.
    $ brew upgrade node
  6. It is also very easy to uninstall node js with homebrew.
    $ brew uninstall nod

Reference

  1. How To Use Node Package Manager
0 0 votes
Article Rating
Subscribe
Notify of
guest

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

8 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Alex George
Alex George

I installed the Node.js by the pkg file downloaded from Node.js official website. And now I want to reinstall the Node.js to the newest version. But when I run the command brew doctor in a terminal, it prompt a warning message, the message is Warning: Unbrewed header files were found in /usr/local/include. If you didn’t put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted. And it lists a lot of unexpected header files under it.

So I uninstall the Node.js follow this article, and reinstall it with the homebrew command brew install node. It is successfully installed the Node.js on my macOS. But the question is when I run the command node -v, it still display the old Node.js version. Can any body give me some help? Does the old version Node.js left files still take effect? Thanks a lot.

Annie
Annie

Is the command to uninstall node with brew correct?

$ brew uninstall nod

I also tried it with ‘node’ thinking it might be a type but neither worked.

Stephanie
Stephanie

Why do you have the word uninstall in the title if you don’t talk about it at all???

Sasha
Sasha

where is Uninstall guide?

Bhavya Shah
Bhavya Shah

Thanks a lot. Saved a lot of time from deleting [email protected] and installing [email protected]

8
0
Would love your thoughts, please comment.x
()
x