How to Upgrade Node.js on Different Operating Systems

Node.js, a popular JavaScript runtime, regularly releases updates to improve performance, fix bugs, and add new features. Staying up-to-date ensures compatibility with new libraries and keeps your system secure. Here’s a step-by-step guide on how to upgrade Node.js on Windows, macOS, and Linux.


1. Upgrade Node.js on Windows

Method 1: Using the Node.js Installer

  1. Visit the official Node.js website.

  2. Download the latest version for Windows (LTS or Current, depending on your needs).

  3. Run the installer:

    • Follow the installation wizard.

    • It will automatically upgrade your existing Node.js version.

Method 2: Using nvm-windows (Node Version Manager for Windows)

  1. Download nvm-windows from the release page.

  2. Install it and ensure it's added to your PATH.

  3. Open a new Command Prompt or PowerShell window and run:


2. Upgrade Node.js on macOS

Method 1: Using Homebrew

  1. Open Terminal.

  2. Run the following commands:

     brew update
     brew upgrade node
    
  3. Verify the version:

     node -v
    

Method 2: Using n

  1. Install n (a version manager) globally if it’s not already installed:

     npm install -g n
    
  2. Use n to install the latest version:

     n latest
    
  3. Verify the version:

     node -v
    

3. Upgrade Node.js on Linux

Method 1: Using NodeSource Repository (Debian/Ubuntu)

  1. Open Terminal.

  2. Add the NodeSource repository:

     curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
    
  3. Install or upgrade Node.js:

     sudo apt-get install -y nodejs
    
  4. Verify the installation:

     node -v
    

Method 2: Using n (for all Linux distros)

  1. Install n globally:

     npm install -g n
    
  2. Use n to install the latest version:

     sudo n latest
    
  3. Check the installed version:

     node -v
    

Method 3: Using nvm (Node Version Manager)

  1. Install or update nvm by running:

     curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
    
  2. Restart your terminal or run:

     source ~/.bashrc
    
  3. Install the latest Node.js version:

     nvm install node
     nvm use node
    
  4. Verify:

     node -v
    
Conclusion
Upgrading Node.js ensures that your applications run with the latest features and security updates. Whether you're on Windows, macOS, or Linux, you can easily upgrade using package managers, version managers, or installers. Choose the method that best fits your workflow, and make sure to regularly update Node.js to avoid compatibility issues.
0
Subscribe to my newsletter

Read articles from ByteScrum Technologies directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

ByteScrum Technologies
ByteScrum Technologies

Our company comprises seasoned professionals, each an expert in their field. Customer satisfaction is our top priority, exceeding clients' needs. We ensure competitive pricing and quality in web and mobile development without compromise.