[macos] Upgrade Node.js to the latest version on Mac OS

Currently I am using Node.js v0.6.16 on Mac OS X 10.7.4. Now I want to upgrade it to the latest Node.js v0.8.1. But after downloading and installing the latest package file from nodejs.org, I found that system is still using v0.6.16 instead of v0.8.1 when I typed "node -v" in a terminal. Is there any step that I have missed? Or, should I thoroughly uninstall the old version before installing the latest one?

BTW, I know that nvm can help to manage the nodejs package

https://github.com/creationix/nvm/

Is there any way to upgrade the Node.js without using it?

I have googled this problem, but it seems to me that there is no very clear answer to this question for the latest Node.js.

This question is related to macos node.js upgrade

The answer is


Go to the website nodejs.org and download the latest pkg then install. it works for me

I used brew to upgrade my node. It has installed but it located in /usr/local/Cellar/node/5.5.0 and there is a default node in /usr/local/bin/node which bothers me. I don't want to make soft link because I don't really know how brew is organized. So I download the pkg file, installed and I got this info:

Node.js was installed at

/usr/local/bin/node

npm was installed at

/usr/local/bin/npm

Make sure that /usr/local/bin is in your $PATH.

Now the upgrade is completed


Upgrade the version of node without installing any package, not even nvm itself:

sudo npx n stable

Explanations:
This approach is similar to Johan Dettmar's answer. The only difference is here the package n is not installed glabally in the local machine.


On macOS the homebrew recommended way is to run

brew install node
npm install -g npm@latest

Screenshot of Terminal Commands


I think the simplest way to use the newest version of Node.js is to get the newest Node.js pkg file in the website https://nodejs.org/en/download/current/ if you want to use different version of Node.js you can use nvm or n to manage it.


These 2 methods I tried are not working:

  1. Use npm

sudo npm cache clean -f

sudo npm install -g n

sudo n stable

  1. Manual install node from official website (https://nodejs.org/en/)

After trying, node -v still shows the old version of node.


Below method works for me:

Step 1: Install nvm (for more details: https://github.com/creationix/nvm#installation)

Open terminal and type this command:

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

Close terminal and reopen it.

Type this command to check if nvm is installed:

command -v nvm

enter image description here

Step 2: To download, compile, and install the latest release of node, type this:

nvm install node ("node" is an alias for the latest version)

To check if node gets the latest version (v10.11.0).

enter image description here

Installing the latest node also installs the latest npm.

Check if npm gets the latest version (6.4.1).

enter image description here


I am able to upgrade the node using following command

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

Go to http://nodejs.org and download and run the installer. It works now - for me at least.


Easy nad Safe Steps

Step 1: Install NVM

brew install nvm

Step 2: Create a directory for NVM

mkdir ~/.nvm/

Step 3: Configure your environmental variables

nano ~/.bash_profile

PASTE BELOW CODE

export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

source ~/.bash_profile

Step 4: Double check your work

nvm ls

Step 5: Install Node

nvm install 9.x.x

Step6: Upgrade

nvm ls-remote

   v10.16.2   (LTS: Dubnium)
   v10.16.3   (Latest LTS: Dubnium) ..........

nvm install v10.16.3

Troubleshooting

Error Example #1
rm -rf /usr/local/lib/node_modules
brew uninstall node
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh

https://www.chrisjmendez.com/2018/02/07/install/


You can directly use curl to upgrade node to the latest version. Run the following command:

curl "https://nodejs.org/dist/latest/node-${VERSION:-$(wget -qO- https://nodejs.org/dist/latest/ | sed -nE 's|.*>node-(.*)\.pkg</a>.*|\1|p')}.pkg" > "$HOME/Downloads/node-latest.pkg" && sudo installer -store -pkg "$HOME/Downloads/node-latest.pkg" -target "/"

Reference: https://nodejs.org/en/download/package-manager/#macos


sudo npm install -g n

and then

sudo n latest for linux/mac users

For Windows please reinstall node.


Nvm Nvm is a script-based node version manager. You can install it easily with a curl and bash one-liner as described in the documentation. It's also available on Homebrew.

Assuming you have successfully installed nvm. The following will install the latest version of node.

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

The last option installs all global npm packages over to your new version. This way packages like mocha and node-inspector keep working.

N N is an npm-based node version manager. You can install it by installing first some version of node and then running npm install -g n.

Assuming you have successfully installed n. The following will install the latest version of node.

sudo n latest

Homebrew Homebrew is one of the two popular package managers for Mac. Assuming you have previously installed node with brew install node. You can get up-to-date with formulae and upgrade to the latest Node.js version with the following.

1 brew update
2 brew upgrade node

MacPorts MacPorts is the another package manager for Mac. The following will update the local ports tree to get access to updated versions. Then it will install the latest version of Node.js. This works even if you have previous version of the package installed.

1 sudo port selfupdate
2 sudo port install nodejs-devel

Simply go to node JS Website and install the latest version.

Do install latest version instead of the recommended stable version. It will give you freedom to use latest ES6 Features on node.

Can be Found here Node JS.

also to update npm, you will have to use this command.

sudo npm i -g npm@latest

All your projects will work fine.

Update: 2020 another good option is to use nvm for node which can then support multiple versions. use nvm install --lts to always be able to update to latest node version use nvm ls-remote command to to check new versions of node.


Other option for mac :: brew update && brew install node && npm -g npm


I was able to update in ~20 seconds with just one line of code

sudo n latest

Other commands weren't working for me, but this one worked. Hope it helps somebody.


for latest release: nvm install node

specific version: nvm install 6.14.4

https://github.com/creationix/nvm


I use Node version manager (called n) for it.

npm install -g n

then

n latest

OR

n stable

Use nvm to upgrade node as per the project requirement..

install nvm through homebrew.. brew update brew install nvm mkdir ~/.nvm nano ~/.bash_profile

In your .bash_profile file (you may be using an other file, according to your shell), add the following :

export NVM_DIR=~/.nvm source $(brew --prefix nvm)/nvm.sh

source ~/.bash_profile echo $NVM_DIR


You can run but you can't hide... At the end you will be using NVM anyways.


If you initially installed Node.js with Homebrew, run:

brew update
brew upgrade node
npm install -g npm

Or as a one-liner:

brew update && brew upgrade node && npm install -g npm

A convenient way to change versions is to use nvm:

brew install nvm

To install the latest version of Node.js with nvm:

nvm install node

If you installed via a package, then download the latest version from nodejs.org. See Installing Node.js and updating npm.


Because this seems to be at the top of Google when searching for how to upgrade nodejs on mac I will offer my tip for anyone coming along in the future despite its age.

Upgrading via NPM
You can use the method described by @Mathias above or choose the following simpler method via the terminal.

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

After which you may opt to confirm the upgrade

node -v

Your nodejs should have upgraded to the latest version. If you wish to upgrade to a specific one say v0.8.19 then instead of

sudo n stable

use

sudo n 0.8.19

EDIT Avoid using sudo unless you need to. Refer to comment by Steve in the comments


You can just go to nodejs.org and download the newest package. It will update appropriately for you. NPM will be updated as well.


You could install nvm and have multiple versions of Node.js installed.

curl https://raw.github.com/creationix/nvm/master/install.sh | sh
source ~/.nvm/nvm.sh

and then run:

nvm install 0.8.22  #(or whatever version of Node.js you want)

you can see what versions you have installed with :

nvm list

and you can change between versions with:

nvm use 0.8.22

The great thing about using NVM is that you can test different versions alongside one another. If different apps require different versions of Node.js, you can run them both.


I had the same problem. This is what worked for me because I downloaded and installed node.js globally from the node.js website.

What I did was Give NVM (Node Version Manager) a try. Please do the commands in the following order in your terminal

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

  2. command -v nvm

  3. nvm install node

  4. node -v (to confirm the update)


This is just to add some info for people who didn't have Node installed with Homebrew but getting that very error when trying to install packages with npm on Mac OS X.

I found this good article explaining how to completely remove Node whichever the way you originally installed it.

After node, npm and n were completely removed from my machine, I just reinstalled Node.js using the official .pckg installer from Node website and everything just went back to normal.

Hope this helps out someone.


sadly, n doesn't worked for me. I use node version manager or nvm and it works like a charm. heres the link on how to install nvm: https://github.com/creationix/nvm#installation

  • nvm i 8.11.2 upgrade to latest LTS
  • nvm use 8.11.2 use it
  • node -v check your latest version

Examples related to macos

Problems with installation of Google App Engine SDK for php in OS X dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac Could not install packages due to an EnvironmentError: [Errno 13] How do I install Java on Mac OSX allowing version switching? Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How can I install a previous version of Python 3 in macOS using homebrew? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"

Examples related to node.js

Hide Signs that Meteor.js was Used Querying date field in MongoDB with Mongoose SyntaxError: Cannot use import statement outside a module Server Discovery And Monitoring engine is deprecated How to fix ReferenceError: primordials is not defined in node UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac internal/modules/cjs/loader.js:582 throw err DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean`

Examples related to upgrade

Problems after upgrading to Xcode 10: Build input file cannot be found Upgrading React version and it's dependencies by reading package.json Want to upgrade project from Angular v5 to Angular v6 Update TensorFlow Table 'performance_schema.session_variables' doesn't exist How to upgrade PostgreSQL from version 9.6 to version 10.1 without losing data? How to upgrade PowerShell version from 2.0 to 3.0 upgade python version using pip How do I update pip itself from inside my virtual environment? How to update Python?