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 -vCheck which version you've got installed.
npm install npm@latest -gInstall the latest version.
npm -vConfirm 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 -fForce NPM to clear its cache. The terminal will ask for your password since this command is using
sudo npm install -g nInstall the "n" package, which lets us install and manage different versions of Node.
sudo n stableInstall the latest stable version of Node.