NodeJS is an open-source JavaScript runtime environment, one of the most popular tools among web developers. Developers typically use NodeJS to improve the functionality of web applications or create local development environments. This tutorial will guide you on how to install Node.JS and NPM on Ubuntu 24.04 using the default repository and NodeSource. You will also learn how to install a specific version of NodeJS using NVM.
Prerequisites
- An Ubuntu 24.04 VPS
- SSH root access or user with sudo privileges
Conventions
# – given commands should be executed with root privileges either directly as a root user or by use of sudo command $ – given commands should be executed as a regular user
class=”wp-block-heading”>Step 1. Login to the server
First, log in to your Ubuntu 24.04 server through SSH as the root user:
ssh master@IP_Address -p Port_number
You must replace ‘IP_Address‘ and ‘Port_number‘ with your server’s IP address and SSH port number. Additionally, replace ‘master’ with the username of the system user with sudo privileges.
You can check whether you have the proper Ubuntu version installed on your server with the following command:
$ lsb_release -a
You should get this output:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu Noble Numbat
Release: 24.04
Codename: noble
Step 2. Install Dependencies
To install NodeJS on our system, we need to install some dependencies. Let’s run the command below to install them.
$ sudo apt install curl apt-transport-https ca-certificates gnupg
Step 3. Install NodeJS and NPM from APT
The easiest way to install NodeJS and NPM on an Ubuntu 24.04 system is from the default APT repository. You will get NodeJS version 18 and NPM version 9 using this installation method. The installation is simple and straightforward. Let’s execute the command below to install NodeJS and NPM.
$ sudo apt install nodejs npm -y
Once installed, you can run this command to check the version.
$ nodejs -v; npm -v
master@ubuntu24:~$ nodejs -v; npm -v v18.19.1 9.2.0
Step 4. Install NodeJS and NPM from NodeSource
We can install NodeJS from the Ubuntu default repository, but we will get an older version of NodeJS if we use this method. Alternatively, we will install NodeJS and npm through NodeJS repository to get the more recent version of it. If compared to Ubuntu’s default repository, NodeSource offer more versions to choose.
$ curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
Once completed, we must download the package information from the newly added source above.
$ sudo apt update
Next, run the following command to install NodeJS and NPM.
$ sudo apt install nodejs
That’s it. NodeJS and NPM are installed. You can check the installed version by executing this one-liner:
$ node -v; npm -v
Now go to https://nodejs.org/en/download/ and see what is the LTS version. You have just installed the same version as shown there, and you will see an output like this after running the command above:
master@ubuntu24:~$ node -v; npm -v v20.11.1 10.2.4
Again, this installation method is suitable if you want to get the LTS or a specific version. For example, if you want version 18, you can execute this command instead.
$ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
Replace 18 with any version you want if you want another version.
Step 5. Install NodeJS and NPM using NVM
Another way to install NodeJS on Ubuntu is by using the Node Version Manager (NVM). NVM is a bash script used to manage several versions of NodeJS on your system. This installation method allows you to install and maintain different independent versions of NodeJS simultaneously.
Run this command below to download the script.
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Then, we need to source the script.
$ source ~/.bashrc
After executing the command, you can list the available version of NodeJS to install with this command:
$ nvm list-remote
The command will return a message containing a long list of NodeJS version to choose.
To install version 20.11.1, run this command
$ nvm install 20.11.1
As explained earlier, you can have multiple version of NodeJS, you can install another version using the same command with the different version in the command.
To switch between the installed version, you can run this command:
$ nvm use 18.19.1
Replace 18.19.1 with the version you want to switch to. Make sure the version is already installed.
Congratulation! You have successfully learned how to install Node.JS and NPM on your Ubuntu 24.04 VPS. For more information about NodeJS and NPM, please refer to the NodeJS website.
If you are still unsure, you don’t have to install NodeJS and NPM On Ubuntu 24.04 yourself. Our Linux admins will set up and configure a NodeJS and NPM VPS for you on our monthly management plans or per incident server support plans.
PS. If you liked this post on how to install NodeJS and NPM On Ubuntu 24.04, please share it with your friends on social networks using the buttons on the left or leave a reply below. Thanks.
The post How to Install Node.js and NPM on Ubuntu 24.04 appeared first on LinuxHostSupport.
Discover more from Ubuntu-Server.com
Subscribe to get the latest posts sent to your email.