I recently installed Node.js and npm, but I realized both are outdated.
I’d like to know the correct way to update npm and Node.js to their latest stable versions without breaking my existing setup.
Should I uninstall and reinstall them, or is there a cleaner upgrade path?
Also, what’s the recommended way to upgrade all globally installed Node.js modules after updating?
Appreciate any tips or commands that simplify the update process!
The safest and cleanest way I’ve found is to use Node Version Manager (nvm).
It lets you install and switch between Node versions easily.
First, install nvm if you haven’t:
bash
Copy
Edit
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Then run:
bash
Copy
Edit
nvm install node # installs latest stable
nvm use node # switches to it
nvm alias default node
This keeps things isolated and avoids permission issues or messing with system binaries.
You can still update npm after that with:
bash
Copy
Edit
npm install -g npm
If you installed Node.js via a package manager like Homebrew (on macOS), updating is pretty seamless:
bash
Copy
Edit
brew update
brew upgrade node
That’ll upgrade both Node and npm together.
After that, I usually run this to update all my global npm packages:
bash
Copy
Edit
npm outdated -g --depth=0
npm update -g
This ensures nothing breaks and keeps your tools synced.
For Windows users, I’ve had good results using the Node.js installer from the official site (https://nodejs.org).
Just download the latest LTS version and run the installer, it updates both Node and npm automatically while keeping global packages intact.
To upgrade global modules afterward:
bash
Copy
Edit
npm install -g npm-check-updates
ncu -g
ncu helps scan and update outdated global packages interactively, great for managing versions without surprises.