Node.js is a JavaScript runtime for server-side programming. It allows developers to create scalable backend functionality using JavaScript, a language many are already familiar with from browser-based web development.

Installing Node.js with Apt from the Default Repositories

Debian contains a version of Node.js in its default repositories that can be used to provide a consistent experience across multiple systems. At the time of writing, the version in the repositories is 10.24.0. This will not be the latest version, but it should be stable and sufficient for quick experimentation with the language.

Warning: The version of Node.js included with Debian 10, version 10.24.0, is unsupported and unmaintained. You should not use this version in production, and should refer to one of the other sections in this tutorial to install a more recent version of Node.

To get Node.js from the default Debian software repository, you can use the apt package manager. First, refresh your local package index:

sudo apt update

Then install the Node.js package:

sudo apt install nodejs

To verify that the installation was successful, run the node command with the -v flag to get the version:

node -v

If the package in the repositories suits your needs, this is all you need to do to get set up with Node.js. In most cases, you’ll also want to also install npm, the Node.js package manager. You can do this by installing the npm package with apt:

sudo apt install npm

This will allow you to install modules and packages to use with Node.js.

PS: The next section will show how to use an alternate repository to install different versions of Node.js.

Installing Node.js with Apt Using a NodeSource PPA

To work with a more recent version of Node.js, you can install from a PPA (personal package archive) maintained by NodeSource

This is an alternate repository that still works with apt, and will have more up-to-date versions of Node.js than the official Debian repositories. NodeSource has PPAs available for multiple Node versions. Refer to the NodeSource documentation for more information on the available versions.

From your home directory, use curl to retrieve the installation script for your preferred Node.js version. If you do not have curl installed, you can install it before proceeding to the next step with this command:

sudo apt install curl

With curl installed, you can begin your Node.js installation. This example installs version 16.x. You can replace 16.x with your preferred version.

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install nodejs

You don’t need to install a separate package for npm in this case, as it is included in the nodejs package.

Verify the installation by running node with the -v version option:

node -v

Update Node.js with NPM

If you want to upgrade Node.js from the command line, use the n model within the npm command. The n feature allows you to interact with different Node.js versions.

1. Before updating the Node.js release, check which version you are currently using with:

node -v

2. Next, clear npm cache with the command:

npm cache clean -f

3. Install n globally:

npm install -g n

4. Now that you have n installed, you can use the module to install the latest stable release of Node.js:

sudo n stable

Alternatively, you can install the Node.js release with the latest features:

sudo n latest

Or, install a specific version number with:

n [version.number]
Reference:

https://www.digitalocean.com/

By Shabazz

Software Engineer, MCSD, Web developer & Angular specialist

Leave a Reply

Your email address will not be published. Required fields are marked *