Upgrade Node.js to the latest version on Mac OS
Here's how I successfully upgraded from v0.8.18
to v0.10.20
without any other requirements like brew etc, (type these commands in the terminal):
sudo npm cache clean -f
(force) clear you npm cachesudo npm install -g n
install n (this might take a while)sudo n stable
upgrade to the current stable version
Note that sudo
might prompt your password.
Additional note regarding step 3: stable
can be exchanged for latest
, lts
(long term support) or any specific version number such as 0.10.20
.
If the version number doesn't show up when typing node -v
, you might have to reboot.
These instructions are found here as well: davidwalsh.name/upgrade-nodejs
More info about the n package found here: npmjs.com/package/n
More info about Node.js' release schedule: github.com/nodejs/Release
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
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.