Posted by Kosal
Node.js is a powerful JavaScript runtime that enables developers to run JavaScript code on the server-side. Installing Node.js on Ubuntu can sometimes require specific steps, especially when aiming to install a particular version. This article provides a comprehensive, step-by-step guide to installing Node.js version 20 on Ubuntu.
sudo apt-get update && sudo apt-get install -y ca-certificates curl gnupg
Begin by updating the list of available packages and installing essential dependencies required for the Node.js installation. This step ensures that the system is up-to-date and has necessary tools like curl
and gnupg
installed.
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
Next, retrieve the GPG (GNU Privacy Guard) key from the NodeSource repository to ensure the authenticity of the Node.js packages. This key will be used to validate the packages during installation.
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
Specify the Node.js version to be installed (in this case, version 20) and add the NodeSource repository to the system's package sources. This step configures the repository URL for the desired Node.js version.
sudo apt-get update && sudo apt-get install nodejs -y
Update the repository lists to include the newly added NodeSource repository and proceed to install Node.js version 20. The -y
flag is used to automatically confirm installation prompts.
After executing the installation commands, verify that Node.js version 20 has been successfully installed by running:
node -v
v20.10.0
By following these step-by-step instructions, users can effortlessly install Node.js version 20 on their Ubuntu system. This process ensures the proper setup of dependencies, retrieval of the necessary GPG key, configuration of the repository, and successful installation of Node.js.
Reference: deb.nodesource.com