How To Update Node And NPM On Windows, Mac, And Linux (2024 Guide)

OpenReplay Tech Blog - Jul 12 - - Dev Community

by Ghaida Bouchaala


Session Replay for Developers

Uncover frustrations, understand bugs and fix slowdowns like never before with OpenReplay — an open-source session replay suite for developers. It can be self-hosted in minutes, giving you complete control over your customer data.

OpenReplay

Happy debugging! Try using OpenReplay today.


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:

- Visit nodejs.org and download the latest Node installer for Windows. - Open the downloaded file and follow the installation steps. This will automatically update Node.js and npm to their latest versions. - Open Command Prompt or PowerShell. - Run node -v or node --version to check the Node.js version - Run npm -v or npm --version to check the Node.js 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**:

  • Open terminal
  • Run brew update
  • Run brew upgrade node This updates Node.js and npm to the latest versions.
  • Run node -v and npm -v in Terminal.

**Using Node.js installer**:

  • Visit nodejs.org and download the installer for macOS.
  • Follow the installation prompts to update Node.js and npm.
  • Open terminal
  • 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)**:


- Open terminal
- Run curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
- Source nvm: source ~/.nvm/nvm.sh

- Run nvm install node to get the latest version.

- Run nvm alias default node

  • 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)


- Check Current Version: Open terminal
- Run node -v to see the current version.

- Run sudo apt-get update
- Run sudo apt-get install -y nodejs

- Run node -v and npm -v

**Using NodeSource repository (Ubuntu/Debian)**:


- Open terminal
- Run curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -

- Run sudo apt-get install -y nodejs

- Run node -v and npm -v

**Using nvm (Node Version Manager)**:

  1. Install nvm: Open terminal and run - 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:
    • Runnvm 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)

Can I install multiple versions of Node.js on my system?
Yes, using Node Version Manager (nvm), you can install and switch between multiple versions of Node.js on your system.

Why might I need to clear npm cache, and how do I do it?
Clearing the npm cache can resolve various issues related to corrupted caches. Run npm cache clean --force to clear the cache.

How do I update npm to a specific version?

You can update npm to a specific version by running npm install -g npm@version, replacing version with the desired version number.

Do I need to uninstall Node.js and npm before reinstalling the latest versions?
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.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .