Installing Node.js Tutorial: Debian Linux
Looking to install Node.js on your Debian-based distro? The folks from NodeSource walk us through installation for Debian Wheezy, Jessie, Stretch, and Sid.
Join the DZone community and get the full member experience.Join For Free
Getting Node.js up and running on your system - be it your development machine or your production environment - is step one to building and deploying Node.js tools, applications, and services.
In this quick tutorial, we'll go over how to get up and running with Node.js on Debian-based distributions. Once we've completed the entirety of the tutorial, you'll be ready to take the next step with Node.js.
This guide covers installing Node.js on Debian 7 (Wheezy), Debian 8 (Jessie), Debian Testing (Stretch), and Debian Unstable (Sid). These are the versions supported by the Node.js Debian binary distributions at the time of this writing.
Step 0: TL;DR - Install Node.js Quickly on Debian
Before we get started, if you just want to get Node.js installed on Debian (specifically Wheezy, Jessie, Stretch, or Sid) fast, here are the two commands you need to run.
# Adding the NodeSource APT repository for Debian-based distributions repository AND the PGP key for verifying packages $ sudo curl -sL https://deb.nodesource.com/setup_6.x | bash - # Install Node.js from the Debian-based distributions repository $ sudo apt-get install -y nodejs
Step 1: Environment Setup - Ensure Your Environment Meets the Basic Requirements to Install Node.js
To be able to install Node.js in a Debian environment, the machine you're installing Node.js on meets the following requirements:
Your Environment Is on a Supported Architecture:
- i386 (32-bit)
- amd64 (64-bit)
- armhf (ARM 32-bit hard-float, ARMv7 and up: arm-linux-gnueabihf)
Your Environment Is Using a Supported Debian Distribution:
- Debian 7 (Wheezy)
- Debian 8 / Stable (Jessie)
- Debian Testing (Stretch - aliased to Jessie)
- Debian Unstable (Sid)
Note: Debian 7 Wheezy on armhf architectures is not supported.
Step 2: Basic Setup: Setting Up the Correct APT Repository to Install Node.js
Let's start working on getting the correct Node.js binary. To do so, you need to add the maintained APT repository for Debian-based Node.js, and add the APT repository's associated PGP key to the system's APT keychain.
This step is necessary, as the repository that
apt-get install nodejs defaults to is severely outdated - it defaults to a Node.js 4 release line that is missing several large security updates.
To set up the recommended APT repository for Node.js that is consistently maintained and updated and update the APT keychain with the APT repository's PGP key most quickly, you can run the following command:
# Download and setup the APT repository add the PGP key to the system’s APT keychain, $ sudo curl -sL https://deb.nodesource.com/setup_6.x | bash -
This script completes both steps of adding the apt-get repository to the system and adds the repository's PGP key to the APT keychain. The Node.js Debian-based distributions are hosted, maintained, and signed by NodeSource, and this script - including the currently run scripts, their commit history, and the scripts for previous versions of the Node.js Debian installer are all publicly available on GitHub. If you want to take a deep dive into understanding how it’s accomplished, go check them out!
Step 3: Running
apt-get to Install Node.js
After the APT repository from Step 2 is set up, we can install Node.js with the standard
apt-get command. Here's the exact command needed:
$ sudo apt-get install -y nodejs
After the command runs successfully, Node.js should now be properly installed on the Debian system!
Step 4: Confirm that Node.js Was Installed Correctly
To make sure that Node.js was installed correctly on your machine, you can run a quick test by using the following command:
$ node -v
If Node.js was correctly installed, you should see something resembling (but probably not exactly matching) this:
$ node -v // The command we’re running v6.9.4
Step 5: Update Your npm Version
One final step for good measure is to update the version of
npm. There's always a specific version of
npm that ships with Node.js. That said, the release cycle of
npm is not in sync with the release cycle of Node.js - as such, there's frequently a newer version of
npm than the one that comes with Node.
To update your version of
npm, simply run the following command:
$ sudo npm install npm --global
Step 6: Start Using Node!
You've now got Node.js - it's time to explore. Luckily, we've got you covered. We've got a bunch of guides to help you get started with Node.js - for example, we've got an article on some of the best ES6 features in Node.js, an awesome post to learn how to lint your Node.js apps with ESLint, a tutorial in two parts to learn to run Node.js applications with systemd, and plenty more!
If you want to keep up to date with Node.js and the Node ecosystem, you should follow @NodeSource on Twitter! We’ll make sure to keep you informed with the latest updates from the Node.js project, and will be sure to let you know about the best Node.js tutorials, guides, and tools!
Published at DZone with permission of Tierney Cyren, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.