Install NodeJS on Debian 10
But before you can build things with it, you'll need to have it installed on your machine.
In this article, we'll walk you through three different ways to install Node.js on a machine running the Debian 10 operating system:
Feel free to skip to whatever section you wish to use.
Let's get started!
Table of Contents
Option 1 — Debian Default Repository
Debian 10 holds a version of Node.js in its default repositories. This won't be the latest version, but it will be stable and sufficient for most use cases.
You can install the Node.js default repository using the
aptcommand. This is a command-line tool that makes things like installing new software packages, upgrading existing software packages, and updating the package list index super easy.
First, we need to ensure all your local package indexes are up-to-date:
$ sudo apt update
aptpackage index is a database of available packages from the repository defined on your system. After running that command, that index on your machine will be updated with all the latest changes made to those repositories.
When that's done updating, you can install Node.js using this command:
$ sudo apt install nodejs
To ensure you've successfully installed Node.js, execute this command:
$ nodejs -v
This will output the version of Node.js you installed.
In most cases, you'll also want to install NPM alongside Node.js. Npm (Node.js Package Manager) is a package manager for Node.js and will allow you to easily install NPM packages and import them into your code.
You can install it with this command:
$ sudo apt install npm
And you can verify you've successfully installed NPM with this command:
$ npm -v
That will output the current version of NPM installed on your machine.
Awesome! You now have Node.js and NPM installed on your Debian 10 machine. In the next sections, we will go over some additional ways to install and configure Node.js that provide some additional features.
Option 2 — NodeSource Node.js PPA (Personal Package Archive)
Another option for installing Node.js on Debian 10 is to use the NodeSource Node.js PPA (Personal Package Archive). This will have a wider collection of Node.js versions for you to choose from to install.
First, you need to use
wgetto get the installation script for the specific Node.js version you want to install.
Make sure you are in your home directory:
$ cd ~
And you can get the installation script and run it with this command (make sure you replace the highlighted portion with whichever version you want):
$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
When that command finishes, the PPA will be added to the configuration on your machine. And you can now install the Node.js package with this command:
$ sudo apt-get install -y nodejs
To ensure everything was installed correctly, check for the version of Node.js currently installed on your machine:
$ nodejs -v
This will output something similar to this:
NPMis included in what you just installed, so you don't need to install it separately.
You can verify
NPMhas been installed with this command:
$ npm -v
It'll output something similar to this:
NPMand the software you install with it works properly in all cases, you should install the build-essential list of packages:
$ sudo apt-get install -y build-essential
Awesome! You now have Node.js and
NPMconfigured on your Debian 10 machine. And you're ready to start coding!
Option 3 — Nvm (Node.js Version Manager) Tool
The third installation method we'll cover is using the Nvm (Node.js Version Manager) tool. This tool will make it easy to install and use multiple versions of Node.js without adding much extra complexity. There will be times when an application needs different versions of Node.js to work, so having the flexibility to change that is important and will save you a lot of time.
To get the
nvminstallation script from their Github page, use either the
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
$ wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
To gain access to using
nvm, you may need to open a new terminal window or log out and back in again:
$ nvm --version
nvmis installed correctly, something similar will be printed to your console:
Now that you have
nvminstalled on your machine, you can install isolated versions of Node.js
You can use this command to see what versions are available to be installed:
$ nvm ls-remote
This will log a huge list of Node.js versions for you to choose from:
. . .
To install a specific version from that list, you can use a command similar to this (replace the yellow text with the version you want to install):
$ nvm install 10.16.3
And you can also use whatever Node.js version you want with this command:
$ nvm use 10.16.3
Now, that version will be used whenever you use Node.js on your machine.
To set one version as the default on your machine, execute this command:
$ nvm alias default 10.16.3
That version you specified will be automatically selected whenever a new session is spawned on your Debian 10 machine.
To learn more about additional options provided by
nvm, type this command in your terminal:
$ nvm help
Node.js is now installed using
nvmon your Debian 10 machine!
As you can see, there are several ways for you to get Node.js installed on your Debian 10 machine.
In this article, we went over three different ways using the default Debian 10 repositories, the Nodesource Node.js PPA, and the Nvm tool.
Thanks for reading and happy coding!