Learning Center
Node.js

How to Update Node.js Version

23 Jan 2025
Awais Khan
Awais Khan

Node.js stands as a robust JavaScript runtime environment powered by Chrome's V8 engine. With its capabilities, developers can construct scalable network applications with simplicity. Renowned for its event-driven, non-blocking architecture, it’s perfect for creating real-time applications.

Regularly refreshing your tools ensures access to the newest features, security fixes, and performance gains. Updating Node.js regularly is crucial for the stability and security of projects, regardless of their scale.

This all-inclusive guide will navigate you through diverse methods to update Node.js, covering everything from package managers to hands-on manual installations.

Method 1: Via NVM
Copy link

Node Version Manager, abbreviated as NVM, is extensively employed for seamless handling of various Node.js versions. Its flexibility and user-friendly interface make it particularly popular among developers. This tool facilitates easy switching between node versions, perfect for projects that demand particular Node.js versions.

Why Use NVM?
Copy link

  • Flexibility: Easily shift from one node version to another.
  • Convenience: Handle installations, updates, and management of various versions effortlessly.
  • Isolation: Isolates different versions to minimize conflicts.

Step-by-Step Guide
Copy link

Adhere to these guidelines to set up and utilize NVM for node version management.

Install NVM

Initiate a terminal session and input:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

Image7

Then configure NVM in your shell profile like Bash:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Next, confirm the NVM installation with:

nvm --version

Image9

Update Version

List available versions first, then proceed with installation:

nvm ls-remote

Image8

Subsequently, install the latest release via:

nvm install node

Image11

Then, set the newly installed version as the default:

nvm alias default node

Image10

Validate the installation through:

node -v

Image13

Update npm

To guarantee superior performance and safety, keep npm up-to-date alongside node:

npm install -g npm

Image12

Lastly, validate the updated npm version for confirmation via:

npm -v

Image15

Switching Node Versions

First, list out the installed versions through:

nvm ls

Image14

Next, switch to another version:

nvm use <version>

Insert the required version number in place of <version>.

And if you’re looking for a reliable, high-performance, and budget-friendly solution for your workflows, Hostman has you covered with Linux VPS Hosting options, including Debian VPS, Ubuntu VPS, and VPS CentOS.

Method 2: Via Node.js Binary Packages
Copy link

Direct installation from Node.js official binaries is hassle-free and secures the specific release straight from the source.

Why Use Binary Packages?
Copy link

  • Simplicity: Achieve direct installation without using additional tools.
  • Consistency: Backed by the official Node.js development team.
  • Reliability: Guarantees the exact release comes from the official source.

Step-by-Step Guide
Copy link

Adopt these guidelines to update Node.js through binary packages.

Obtain the Binary Package

Access the Node.js website and grab the binary package compatible for your particular OS.

Image18

Install Node.js

Finish the installation by adhering to the guidelines specific to your OS:

  • Windows: Run the installer and finish by following the on-screen steps.
  • macOS: Execute the .pkg file and continue via the setup process.
  • Linux: Unpack the tarball and transfer the contents to /usr/local.
tar -xvf node-v<version>-linux-x64.tar.xz

Image16

sudo cp -r node-v<version>-linux-x64/bin /usr/local/

Image17

Next, access the .bashrc file:

nano ~/.bashrc

Then, insert the lines below:

export PATH="/usr/local/bin:$PATH"

Save the file and use source to update settings:

source ~/.bashrc

Verify Installation

Validate the installation via:

node -v

Image19

Check npm release:

npm -v

Image20

Method 3: Via Package Managers
Copy link

Homebrew and apt facilitate Node.js installation and updates by handling dependency and version management.

Why Use Package Managers?
Copy link

  • Ease of Use: Simplifies installation and updates.
  • Automation: Handles dependencies and version management.
  • Integration: Easily integrates with other software and systems.

Step-by-Step Guide
Copy link

Apply these procedures to upgrade Node.js via package managers.

Via Homebrew (macOS)

Employ the instructions on the Homebrew website if not already installed.

Enter the subsequent command:

brew install node

For upgrading the existing installation:

brew upgrade node

Validate the current installation:

node -v

Via apt (Ubuntu/Debian)

Include the node’s PPA in your system setup:

curl -fsSL https://deb.nodesource.com/setup_23.x | sudo -E bash -

Image21

Update 23.x to the desired release.

Enter the subsequent command:

sudo apt install nodejs

Image22

Check that the node release is correct:

node -v

Image23

Method 4: Via Node.js Version Manager (n)
Copy link

The n package offers an efficient method for managing Node.js versions, serving as an alternative to NVM. This tool transforms the way you install, switch, and maintain different node versions on your system.

Why Use n?
Copy link

  • Efficiency: Fast and lightweight.
  • Simplicity: User-friendly and requires minimal commands.
  • Control: Complete control over the versions set up.

Step-by-Step Guide
Copy link

Here's how to configure and use the n package for managing node versions.

Install n

Run npm to globally install the n package:

npm install -g n

Image24

Install or Update Node.js

Install the latest node release:

sudo n latest

Image25

Install a specific release:

sudo n <version>

Change <version> to the required release number.

Verify Installation

Confirm version:

node -v

Image26

Method 5: Manual Installation
Copy link

Manual installation suits advanced users seeking complete control over the setup.

Why Use Manual Installation?
Copy link

  • Control: Complete authority over the installation workflow.
  • Customization: Customize the build and installation settings.

Step-by-Step Guide
Copy link

Adhere to these guidelines for manual installation:

Install Dependencies

Install essential dependencies first via:

sudo apt install build-essential gcc g++ make

Download Source Code

Head over to the official website and obtain the source code.

wget https://nodejs.org/download/release/v23.6.0/node-v23.6.0.tar.gz

Image1

Build and Install

Extract the source code:

tar -xvf node-v<version>.tar.gz

Image2

Replace <version> with the version number.

Navigate to the extracted directory:

cd node-v<version>

Configure and compile the source code:

./configure

Image3

make

Image4

Install the tool:

sudo make install

Image5

Verify Installation

Confirm version:

node -v

Image26

Additional Resources
Copy link

For in-depth information on Node.js updates and management, consider these resources:

  • Documentation: Comprehensive resource for all Node.js things.
  • NVM GitHub Repository: Extensive support and information for NVM.
  • n GitHub Repository: Information on applying the n package for node version control.
  • Release Notes: Remain informed about the newest enhancements and updates.

Best Practices
Copy link

  • Regular Checks: Make it a habit to regularly check for node updates to ensure your environment is always up-to-date.
  • Backup: Always create backups of your projects and important data before updating to safeguard against any loss during the upgrade.
  • Testing: Upon completing the update, thoroughly test your applications to verify they function correctly with the new node release.
  • Documentation: Keep your project documentation in sync with the latest Node.js release and note any changes from the update.

Fixing Common Problems
Copy link

Running into problems while updating Node.js? Discover frequent issues and effective fixes:

Issue 1: Version Not Changing 

In case the node version stays the same after updating, attempt the following:

Clear npm cache:

npm cache clean -f

Reinstall node using the desired method.

Issue 2: Permission Errors 

If permission problems occur, use sudo for elevated command execution:

sudo npm install -g n

Issue 3: Dependency Conflicts 

Sometimes, updating the application can result in conflicts with dependencies in your current projects. 

To resolve this:

  • Utilize nvm to pick the necessary release for each project.
  • Ensure dependencies in your project are updated to align with the new Node.js release.

Conclusion
Copy link

There are various methods available to update Node.js, each suited to specific needs and preferences. Whether it's NVM, binary packages, package managers, the n package, or manual installation, you can keep your dev environment up-to-date with the newest features and security fixes. Frequent updates are always a key factor to maintaining top performance and safety.

Consistently update Node.js to benefit from the latest features, security enhancements, and performance boosts for robust and secure applications. Using this in-depth guide, you can expertly handle and update your node installations according to your specific needs and preferences.

In addition, check out our platform as a service to deploy various Node.js frameworks, such as Express, Fastify, Hapi and Nest.