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 ninstall n (this might take a while)sudo n stableupgrade 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
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 ninstall n (this might take a while)sudo n stableupgrade 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
Using Homebrew
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
Using n
A convenient way to change versions is to use n:
brew install n
To install the latest version of Node.js with n:
n latest
Or, to install the latest LTS version with n:
n lts
Using nvm
Alternatively, you could use nvm instead of n:
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.
Videos
Is /usr/local/bin/npm a broken symlink? That would make sudo npm print an error like command not found and npm print an error like No such file or directory.
You could try creating a new symlink for node:
$ rm /usr/local/bin/npm; brew unlink node; brew link node
Unlinking /usr/local/Cellar/node/0.10.5... 4 links removed
Linking /usr/local/Cellar/node/0.10.5... 5 symlinks created
$ sudo /usr/local/bin/npm uninstall npm -g
Or use /usr/local/opt/node/bin/npm:
$ ls -l `brew --prefix node`
lrwxr-xr-x 1 lauri admin 21 Jun 14 18:27 /usr/local/opt/node -> ../Cellar/node/0.10.5
$ sudo /usr/local/opt/node/bin/npm uninstall npm -g
I realize this is years old, but after dealing with these sorts of file permission and package manager problems myself for many years, a buddy of mine and I created a rather simple solution that works without sudo, and without relying on brew or other package managers.
Install with webi
On Mac or Linux:
curl -s https://webinstall.dev/node@stable | bash
Or, on Windows 10 (which now includes curl.exe - so no msysgit or cygwin needed):
curl.exe -sA "MS" https://webinstall.dev/node@stable | powershell
More info at https://webinstall.dev/node (also has a link to the source for the bash and powershell)
Upgrade / Switch Versions
And then you can switch versions (upgrade, downgrade, etc) like this:
webi node # 'stable' is the default tag
webi node@lts # long-term support
webi node@v10 # specifically the latest of v10
Doing the same by hand
webi is just a small helper / bootstrap script in bash (or powershell on Windows 10), and you could do the same by hand:
- Check the node.js releases API: https://nodejs.org/dist/index.tab
- Get the desired version: https://nodejs.org/dist/latest/
- Unpack to
$HOME/.local/opt/node - Add
$HOME/.local/opt/node/binto yourPATH- (in
.zshrc,.bashrc,.profile, the Windows Registry, or withpathman)
- (in
- On macOS 10.14+ you may need to use
xattr -r -d com.apple.quarantine ~/.local/opt/node/bin/node
Then when you need to update versions, remove the node directory (rm -rf ~/.local/opt/node) and then repeat the above steps with the new version.
Note: This requires re-installing any global tools, such as jshint or prettier.