/

How to Upgrade Node.js on Ubuntu: A Step-by-Step Guide

How to Upgrade Node.js on Ubuntu: A Step-by-Step Guide

If you’re running a Node.js service on Ubuntu and find yourself stuck on an outdated version, it’s time to upgrade. Upgrading to the latest available version is crucial for accessing new features, bug fixes, and security updates. In this guide, we’ll walk through the process of upgrading Node.js on Ubuntu.

Step 1: Update Node.js Repository

To update Node.js on Ubuntu, we need to add the Node.js repository to the system by running the following command:

1
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -

This command will fetch and execute the script required for updating the repository.

Tags: Node.js upgrade, Ubuntu, repository, setup script

Step 2: Install the Latest Version

Once the repository is updated, we can proceed to install the latest version of Node.js using the apt-get command:

1
sudo apt-get install -y nodejs

Running this command will install the updated Node.js package on your Ubuntu system.

Tags: Node.js upgrade, Ubuntu, installation, package manager

Step 3: Specify Desired Version (Optional)

By default, the repository script mentioned above points to the LTS (Long-Term Support) version of Node.js. However, if you wish to install a different version, you can modify the script accordingly.

For example, to install the current version, replace setup_18.x in the repository script URL with setup_19.x.

1
curl -sL https://deb.nodesource.com/setup_19.x | sudo -E bash -

Similarly, if future versions like 20 or 21 have been released, you can simply update the number accordingly.

Tags: Node.js upgrade, Ubuntu, LTS version, specific version

Conclusion

Upgrading Node.js on Ubuntu is a straightforward process that involves updating the Node.js repository and installing the latest version. By following the steps outlined in this guide, you can ensure that your Node.js service benefits from improved functionality and security.

Tags: Node.js upgrade, Ubuntu, LTS version, latest version