Back

How to Update Node and NPM on Windows, Mac, and Linux (2024 Guide)

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:

  1. Download the latest Node.js installer: Visit nodejs.org and download the latest node installer for Windows.
  2. Run the installer: Open the downloaded file and follow the installation steps. This will automatically update Node.js and npm to their latest versions.
  3. Verify the installation: Open command prompt or powerShell and run node -v to check the Node.js version. Run npm -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

  1. Update homebrew: Open terminal and run brew update.
  2. Upgrade Node.js: Run brew upgrade node to update Node.js and npm to the latest versions.
  3. Verify the installation: Run node -v and npm -v in Terminal.

Using Node.js installer

  1. Download the latest Node.js installer: visit nodejs.org and download the installer for macOS.
  2. Run the installer: Follow the installation prompts to update Node.js and npm.
  3. Verify the installation: Run node -v and npm -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)

  1. 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
  2. Install the latest Node.js: Run nvm install node to get the latest version.
  3. Set default Node.js version: Run nvm alias default node
  4. Verify the installation: Run node -v and npm -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)

  1. Check current version: Open terminal and run node -v to see the current version.
  2. Update Node.js using apt: Run sudo apt-get update and then sudo apt-get install -y nodejs
  3. Verify the installation: Run node -v and npm -v

Using NodeSource repository (Ubuntu/Debian)

  1. Add NodeSource repository: Open terminal and run curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
  2. Install Node.js: Run sudo apt-get install -y nodejs
  3. Verify the installation: Run node -v and npm -v

Using nvm (node version manager)

  1. 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
  2. Install the latest Node.js: Run nvm install node
  3. Set default Node.js version: Run nvm alias default node
  4. Verify the installation: Run node -v and npm -v

How to update npm separately

If you only need to update npm without updating Node.js, follow these steps (applicable on all platforms):

  1. Open terminal or command prompt.
  2. Run the command: npm install -g npm
  3. 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.

Listen to your bugs 🧘, with OpenReplay

See how users use your app and resolve issues fast.
Loved by thousands of developers