How to Update Node and NPM on Windows, Mac, and Linux (2024 Guide)
If you have already installed Node.js and need to update it to a newer version, or if you’re experiencing errors due to an outdated version of Node.js, this article covers almost all effective methods for updating Node.js and npm on Windows, Mac and Linux in 2024.
We will focus on the most reliable and straightforward approaches. Follow these steps to make sure your development environment is up to date and working properly.
How to update Node and NPM on Windows
Using the Node.js installer is the simplest and most recommended approach to update Node and NPM to their latest versions on Windows. Here are the steps:
- Download the latest Node.js installer: Visit nodejs.org and download the latest node installer for Windows.
- Run the installer: Open the downloaded file and follow the installation steps. This will automatically update Node.js and npm to their latest versions.
- Verify the installation: Open command prompt or powerShell and run
node -v
to check the Node.js version. Runnpm -v
to check the npm version.
How to update Node and NPM on Mac
You can update Node.js and NPM on a Mac using Homebrew, the Node.js installer, or nvm (Node Version Manager).
Using Homebrew
- Update homebrew: Open terminal and run
brew update
. - Upgrade Node.js: Run
brew upgrade node
to update Node.js and npm to the latest versions. - Verify the installation: Run
node -v
andnpm -v
in Terminal.
Using Node.js installer
- Download the latest Node.js installer: visit nodejs.org and download the installer for macOS.
- Run the installer: Follow the installation prompts to update Node.js and npm.
- Verify the installation: Run
node -v
andnpm -v
Once the installation has completed successfully, you will see this message
This package has installed
- Node.js vX.x.x to /usr/local/bin/node
- npm vX.x.x to /usr/local/bin/npm
Make sure that /usr/local/bin is in your $PATH.
Using nvm (node version manager)
- Install nvm: Open terminal and run
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
. Source nvm:source ~/.nvm/nvm.sh
- Install the latest Node.js: Run
nvm install node
to get the latest version. - Set default Node.js version: Run
nvm alias default node
- Verify the installation: Run
node -v
andnpm -v
How to update Node and NPM on Linux
You can update Node.js and npm on Linux using apt
, the NodeSource repository, or nvm (Node Version Manager).
Using apt (Ubuntu/Debian)
- Check current version: Open terminal and run
node -v
to see the current version. - Update Node.js using apt: Run
sudo apt-get update
and thensudo apt-get install -y nodejs
- Verify the installation: Run
node -v
andnpm -v
Using NodeSource repository (Ubuntu/Debian)
- Add NodeSource repository: Open terminal and run
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
- Install Node.js: Run
sudo apt-get install -y nodejs
- Verify the installation: Run
node -v
andnpm -v
Using nvm (node version manager)
- Install nvm: Open terminal and run
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
. Source nvm:source ~/.nvm/nvm.sh
- Install the latest Node.js: Run
nvm install node
- Set default Node.js version: Run
nvm alias default node
- Verify the installation: Run
node -v
andnpm -v
How to update npm separately
If you only need to update npm without updating Node.js, follow these steps (applicable on all platforms):
- Open terminal or command prompt.
- Run the command:
npm install -g npm
- Verify the installation: Run
npm -v
Conclusion
In conclusion, whether you want to update or upgrade Node.js and npm, these methods will ensure you have the latest versions on Windows, Mac, or Linux. Using the Node.js installer is the simplest and most reliable method. Alternatively, package managers like Homebrew, nvm, or apt will also automatically update both Node.js and npm.
Frequently asked questions (FAQs)
Yes, using Node Version Manager (nvm), you can install and switch between multiple versions of Node.js on your system.
Clearing the npm cache can resolve various issues related to corrupted caches. Run npm cache clean --force to clear the cache.
You can update npm to a specific version by running npm install -g npm@version, replacing version with the desired version number.
In most cases, you don't need to uninstall Node.js and npm before upgrading. The installation process for newer versions typically overwrites the existing installation. However, if you're experiencing issues with your current installation, a clean install (uninstalling first) might be recommended.