Question

How do I update the node version to 20.9.0

Following the tutorial https://www.digitalocean.com/community/tutorials/how-to-deploy-a-nestjs-application-with-nginx-on-ubuntu. To fulfill the prequesit of installing node I used the command: sudo apt install nodejs This installed node 18.19.1. On my local machine I am using 20.9.0. How do I upgrade to this version

At the end of the day I would like to get my dockerised nestjs api deployed from github but am assuming I need node there first


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
May 20, 2024

Heya,

To upgrade Node.js to a specific version like 20.9.0 on your Ubuntu server, you typically need to use a version management tool like Node Version Manager (NVM) or the NodeSource binary distributions. These tools allow you to install and switch between multiple Node.js versions easily. Since you’re using a newer version that might not be available in the default Ubuntu repositories, using NVM is a particularly flexible approach.

Using NVM (Node Version Manager)

NVM allows you to install and manage multiple versions of Node.js. Here’s how to set it up and use it to install Node.js version 20.9.0:

  1. Install NVM: You can install NVM by using the curl or wget command. Open your terminal and type:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

This will download and run the installation script. The script will clone the NVM repository to ~/.nvm and add the source line to your profile (~/.bashrc, ~/.zshrc, ~/.profile, or ~/.bash_profile).

  1. Source Your Profile: To start using NVM immediately, source your profile:
source ~/.bashrc
  1. Install Node.js: Now you can install Node.js version 20.9.0:
nvm install 20.9.0
  1. Use Node.js 20.9.0: After installation, you can switch to the newly installed version with:
nvm use 20.9.0
  1. Check Node Version: Confirm that the correct version of Node.js is installed:
node -v
Bobby Iliev
Site Moderator
Site Moderator badge
May 19, 2024

Hey!

One option is to follow the steps here:

https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04#option-2-installing-node-js-with-apt-using-a-nodesource-ppa

First, install the PPA to get access to its packages. From your home directory, use curl to retrieve the installation script for your preferred version, making sure to replace 20.x with your preferred version string (if different):

cd ~
curl -sL https://deb.nodesource.com/setup_20.x -o /tmp/nodesource_setup.sh
sudo bash /tmp/nodesource_setup.sh
sudo apt install nodejs

Another way of installing Node.js that is particularly flexible is to use nvm, the Node Version Manager. This piece of software allows you to install and maintain many different independent versions of Node.js, and their associated Node packages, at the same time:

https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04#option-3-installing-node-using-the-node-version-manager

Let me know how it goes!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel