How To Install Node.js and NPM on Debian 11 server

Node.js is an open-source JavaScript library built on Chrome’s V8 engine and is primarily used for back-end API services and other server-side applications. Along with React, Node.js is one of the most popular technologies in the world of front-end web development in 2022.

In this tutorial, we will demonstrate two easy ways to to install Node.js and NPM on a Debian 11 server. For the purpose of this writing this tutorial, we have used and tested all commands in a VPS server running Debian 11 64-bit.

Tutorial Pre-requisites

  • Linux machine running Debian 11 OS
  • Root access (or alternative user with root/sudo privileges)

2 Easy Ways To Install Node.js and NPM on Debian 11 Server

First connect via SSH on your server, and ensure all Debian packages are up-to-date. You can do so by executing the following commands:

root@netshopisp-vps:~# apt update && apt upgrade -y

Now that our Debian 11 environment is fully up to date we can proceed to installing Node.js and NPM. We will demonstrate three different, easy ways.

Method 1: Install Node.js and NPM via Debian Repository

The following command will install both packages at once. This is the simplest and most reliable way.

Note that at the time of writing this tutorial (November 2022), Node.js version 12.22 is included by default on Debian’s repositories.

root@netshopisp-vps:~# apt install nodejs npm

As soon as both packages are installed, you can verify their version by executing the following commands:

root@netshopisp-vps:~# node -v
root@netshopisp-vps:~# npm -v

Method 2: Install Node.js and npm from NodeSource

The second method requires a bit more effort than the first, however in case you want to install a specific version of NodeJS and/or NPM, then this method is preferred.

NodeSource maintains an APT repository with multiple Node.js versions.

First command will install ‘curl’ in our system:

root@netshopisp-vps:~# apt install curl -y

We are going to download and run the Node.js installation script for version 16.
If you want another version of Node.js (for example 14.x) just change the setup_16.x with setup_14.x.

root@netshopisp-vps:~$ curl -sL https://deb.nodesource.com/setup_16.x | bash -

Now, install the Node.js version 16 with the following command:

root@netshopisp-vps:~# apt install nodejs

The Node.js package contains both the node and npm binaries. Once installed, verify the installed version of Node.js with the same commands as mentioned earlier in this tutorial.

root@netshopisp-vps:~# node -v
root@netshopisp-vps:~# npm -v

Congratulations! You have now installed Node.JS and NPM on your Debian 11 server. Both two methods we demonstrated are easy and fast to install.

Source: https://netshop-isp.com.cy/blog/how-to-install-node-js-and-npm-on-debian-11-server/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store