In this article, you will review how to get started with Node.js on Debian 10, installing Node from the default Debian repository by personal Package Archives repository, and using Node Version Manager to install and activate different versions of Node. And of course, we do not forget to show you how to uninstall these different versions of Node.
The tutorial may be more useful if you know:
- a non-root user with sudo privileges and a firewall configured with ufw.
- To set up, follow our Initial Setup with Debian 10
Table of Contents
How to install Node.js on Debian 10
Let’s walk through the following steps to begin and finalize Node.js installation.
You may be interested in:
Installing the official Debian Node.js package
Since this version is 10.15.2 and the date of April 1, 2021, will be its life end, you will be no longer supported with security and bug fixes. As Debian contains a version of Node.js in its default repositories, you can install it from the Debian repo to make it sense. So to get Node.js from the default Debian software repository, you can use the apt package manager
To refresh your local package index, run the below command.
sudo apt update
Next, install the Node.js package, and npm the Node Package Manager:
sudo apt install nodejs npm
You can check the installation process by running the node command with the -v flag to get the version.
Installing Using a PPA
If you want to work with an alternate repository, you can install from PPA (personal package archive) maintained by NodeSource. It still works with apt and will have more up-to-date versions of Node.js than the official Debian repositories. When you install PPA, this will add the repository to our package list and allow us to install the new packages using apt.
cd ~ curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh
Note: Ensure to replace 12.x with your preferred version string.
To verify the contents of this script with nano (or your preferred text editor) :
Then, run the script using sudo and exit your text editor.
sudo bash nodesource_setup.sh
Now you can install the nodejs package in the same way, as the PPA will be added to your configuration and your local package cache will be updated automatically.
sudo apt install nodejs
To verify the installation by running node with the -v version option, type:
Run the following command to verify that npm is installed and to create the configuration file:
Since you need the npm packages to work, you will need to install the build-essential package:
sudo apt install build-essential
Installing Using NVM
The other alternative to installing Node.js through apt is to use a tool called Node Version Manager (nvm). You can install multiple self-contained versions of Node.js without affecting the entire system. While you are controlling your environment with nvm, you are able to access the newest versions of Node.js while also retaining and managing previous releases.
Please note that the version number may differ from the highlighted below.
curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh -o
To verify the installation script with nano:
Then, run the script using bash and exit your text editor.
Now, you need to log out and log back in again or source the ~/.profile file to access the nvm functionality and let the session knows about the changes.
Since the nvm is installed, you can install isolated Node.js versions, by typing the below command, you will get information about the versions of Node.js that are available.
. . . v10.16.2 (Latest LTS: Dubnium) v11.0.0 v11.1.0 v11.2.0 v11.3.0 v11.4.0 v11.5.0 v11.6.0 v11.7.0 v11.8.0 v11.9.0 v11.10.0 v11.10.1 v11.11.0 v11.12.0 v11.13.0 v11.14.0 v11.15.0 v12.0.0 v12.1.0 v12.2.0 v12.3.0 v12.3.1 v12.4.0 v12.5.0 v12.6.0 v12.7.0 v12.8.0
Then, install the latest version.
nvm install 10.16.2
nvm, would use the most recently installed version by default. You can also tell nvm to use the version you just downloaded
nvm use 10.16.2
To verify the Node.js version currently being used or not, use the below command.
In case, you have multiple Node.js versions, you can see what is installed.
And if you want to default to a specific version.
nvm alias default 10.16.2
When a new session spawns, this version will be automatically selected.
nvm use default
Finally, it is time to learn how to remove versions installed from the Debian repository or from the PPA. Depending on the version you want to target, you can uninstall Node.js using apt or nvm. So you will need to work with the apt utility at the system level.
sudo apt remove nodejs
To continue, you need to determine the version you would like to remove is the currently active version or not, so, run the following command.
If the currently active version and the version you are targeting are not the same, type
nvm uninstall node_version
If the currently active version and the version you are targeting are the same, deactivate nvm to enable your changes.
As you see, there are a few ways to get up and running with Node.js on your Debian 10 server. Depending on the circumstances, you can choose one of the methods you learned in this article. But installing from a PPA and working with npm or nvm offers additional flexibility.
Dear user, we wish this tutorial would be helpful for you, to ask any question or review the conversation of our users about this article, please visit Ask page. Also to improve your knowledge, there are so many useful tutorials ready for Eldernode training.