Node.js is a platform built on Chrome’s V8 JavaScript engine.Nodejs can used for easily building fast, scalable network applications. The latest version node.js ppa is maintaining by its official website. We can add this PPA to Debian 11 (Bullseye), Debian 10 (Buster), Debian 9 (Stretch) and Debian 8 (Jessie) systems. Use this tutorial to install latest Nodejs & NPM on Debian 10/9/8/7 systems.

Advertisement

To install specific nodejs version, Visit our tutorial Install Specific Nodejs Version with NVM.

Step 1 – Add Node.js PPA

You are required to add Node.js PPA to your system provided by the Nodejs official website. We also need to install the software-properties-common package if not installed already. You can choose either to install the latest Node.js version or LTS version.

For Latest Release

sudo apt-get install curl software-properties-common 
curl -sL https://deb.nodesource.com/setup_18.x | sudo bash - 

For LTS Release

sudo apt-get install curl software-properties-common 
curl -sL https://deb.nodesource.com/setup_16.x | sudo bash - 

Step 2 – Install Node.js on Debian

After adding the required PPA to your system, install the Nodejs package. NPM will also be installed with node.js. This command will also install many other dependent packages on your system.

sudo apt-get install nodejs 

Step 3 – Check Node.js Version

After completing the installation, check and verify the installed version of Node.js and NPM. You can find more details about current version on node.js official website.

node -v  

v18.7.0

Also, check the version of NPM.

npm -v  

7.13.0

Step 4 – Create Demo Web Server (Optional)

This is an optional step. If you want to test your node.js install. Let’s create a web server with “Hello World!” text. Create a file http_server.js

vim http_server.js 

and add the following content

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(3000, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3000/');

Now start the node service using the following command.

node http_server.js 

Server running at http://127.0.0.1:3000/

The web server has been started on port 3000. Now access http://127.0.0.1:3000/ url in browser.

Share.

22 Comments

  1. Daniel Ellis on

    Great write-up.
    I really appreciate the way you have written and explained. Worth reading it.
    Thanks for sharing it with us.
    Good work..!

  2. Nice clean explanation, about the same I’ve seen the last few days, but it still does not work for me!

    Debian 10, actually Raspberrium running on old iMac. No mater what I try, after I add the LTS release (setup_12.x) , the apt-get update will show the correct targets.

    But when I do apt-get install nodejs, it will default back to the debian package (v10.15.2) which creates segmentation faults on a yarn install command.

    I don’t know if its the raspberrium packages but it will alway go to the default, even if I purge nodejs.

    I’ve pushed this truck up to hill so many time with the same results – I’m just lost
    (https://www.cs.uni.edu/~mccormic/humor.html)

    • I’ll comment to myself!

      Well if I would have read a little further I would of let the ‘raspian’ comment sink in. I assumed it was running 64 bit(dual core), but all the packages are 32bi – guess raspian in build from 32 bit debian.

      Guess it was a bad choice for staging server, guess I’ll have to install pure Debian on it

  3. on raspbian

    ## Installing the NodeSource Node.js 12.x repo…

    ## You appear to be running on ARMv6 hardware. Unfortunately this is not currently supported by the NodeSource Linux distributions. Please use the ‘linux-armv6l’ binary tarballs available directly from nodejs.org for Node.js 4 and later.

    the 12 version don’t have an armv6, wath can I do?

  4. Thanks, it is working.
    @AuronStrc I’m using Debian as well – but buster/sid.
    However, do install proposed official Nodejs repo, than you will have latest or LTS version.
    Best,
    Frank

  5. Debian v9.7:

    root@debian:/tmp# node -v
    -bash: node: command not found

    root@debian:/tmp# npm -v
    -bash: npm: command not found

    root@debian:/tmp# nodejs -v
    v4.8.2

    ..what’s wrong?

  6. On Raspbian (Debian Stretch) :
    sudo apt-get install curl python-software-properties

    doesn’t work, should be :
    sudo apt-get install curl software-properties-common

Leave A Reply