How to update NPM and Node.js
⚠️ Note: I did this on MacOS. I have no idea if it will work on Windows or Linux.
In my previous post I covered how to get set up with Node.js and NPM. It's been a full 2 days since then, and in the meantime there's been an update that caused the Node app I cloned to fail.
The most straight forward solution I found was to use the n package in NPM to update Node.
Update NPM #
First make sure NPM (Node Package Manager) is up to date.
npm -v
Check which version you've got installed.npm install npm@latest -g
Install the latest version.npm -v
Confirm that it was updated.
The version number might not change if you already had the latest version. This happened to me. No harm done.
Update Node.js #
Next focus on Node.js.
sudo npm cache clean -f
Force NPM to clear its cache. The terminal will ask for your password since this command is usingsudo
.sudo npm install -g n
Install the "n" package, which lets us install and manage different versions of Node.sudo n stable
Install the latest stable version of Node.