Let’s start with the prerequisites you will need on your Ubuntu server before you install Node.js.
Firstly, you will need an up-to-date operating system. It does not have to be the most recent version, but the more recent, the better. If it can be the newest version, then that would be best;
Next is either a root-level user on the server or a user with sudo privileges. We recommend the latter option, as a user with full root-level access, is only optimal if you are entirely certain how to use it and what damage it can cause.
And that is it. Those are the only two prerequisites for installing Node.js on an Ubuntu server. Next, the actual installation. There are three methods, and they all involve running specific commands in the home directory of your server.
Package Manager - Your Ubuntu server already has a package manager that can be used to install Node.js. You can use the commands below to install it:
sudo apt update - This command will refresh the local package index;
sudo apt install nodejs - The command will install Node.js automatically;
node -v - This command will show you the version of the currently installed Node.js. If you receive an output that shows the version the installation was successful;
sudo apt install npm - This will install NPM on the server. We recommend you install it now, even if you may not need it immediately.
NodeSource - This method will allow you to install a specific version of Node.js in case you want to have something different than the newest one. To do that, run the following commands in the home directory of your server:
curl -sL https://deb.nodesource.com/setup_16.x -o /tmp/nodesource_setup.sh - This command will download the Node.js PPA (Personal Package Archive) to your server. You can see the version is specified in the setup_16.x portion of the command. You can change it to the version you need, with a list of versions supported by NodeSource available on their website;
sudo bash /tmp/nodesource_setup.sh - This command will execute the PPA you downloaded and install the Node.js package on your server. It will not install Node.js, however. The following command will do that;
sudo apt install nodejs - Finally, run this command to install Node.js. You can also use the version command from the previous method to verify the installation. As with the method earlier, NPM is included in the installation.
Node Version Manager - The Node Version Manager (NVM) is a flexible solution for installing and managing Node.js versions, as the name suggests. It allows you to install Node.js and control which version the server uses. If a version is missing, you can install it with a simple command. For our purposes, however, this is what you need to do to install Node.js via NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash - This will download the latest NVM version to your server and install it. At the time of writing, v0.39.5 is the latest one, but you should check the README.md file in this repository for the latest version. After the installation is successful, close or refresh your current terminal, after which you can use NVM. It has many commands, but we will focus on the ones that install Node.js;
nvm list-remote - This will show you which Node.js versions are available for installation;
nvm install v20.5.1 - The command will install the specified version of Node.js on your server;
nvm list - This will show you all Node.js versions that are installed on your server;
nvm use - Finally, you can use this command to switch between Node.js versions. Simply specify the version you saw in the previous command.
As you can see, installing Node.js on Ubuntu is pretty straightforward. In the next section, we will discuss installing it on RedHat distributions, where the process is just as easy.
To provide you with the best experience, our website uses cookies. By continuing to browse the site you are agreeing to our
Cookie Policy.
Your Privacy and Cookies Settings
Our sites use tools, such as cookies, to understand how you use our services and to improve both
your experience and our advertising relevance. Here, you can opt-out of such tracking:
Social
Social media features, such as the ‘Facebook Like/Share button’, Widgets or interactive mini-programs run on our
site to incorporate social and customer feedback feeds. Some of them use cookies for behavioral analytics
and advertising and/or market research.
Support
FastComet Live Chat support requires cookies for behavioral analytics needed to address pre-sales/support inquiries.
Disabling this cookie will limit you from receiving assistance from the Customer Service team via FastComet's LiveChat services.
Statistics and Advertising
We use digital tools, such as Google Analytics, to track web traffic and the effectiveness of our digital
advertising outreach efforts. This helps us identify more relevant ads to consumers and to improve
the efficiency of our marketing campaigns.
Essential
Cookies required for essential services and functionality such as login forms, shopping cart integration,
and access control. Without them, our website cannot function properly and we cannot provide any service.
Opt-Out is not available.
By continuing to browse the site you are agreeing to our
and Cookie Policy.