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 the Debian 12 (Bookworm), Debian 11 (Bullseye), and Debian 10 (Buster) Linux systems. Use this tutorial to install latest Nodejs & NPM on Debian 12/11/10 systems.

Advertisement

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

Install nodejs on Debian

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_21.x | sudo bash - 

For LTS Release

sudo apt-get install curl software-properties-common 
curl -sL https://deb.nodesource.com/setup_20.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  

v20.10.0

Also, check the version of NPM.

npm -v  

10.2.3

Step 4 – Create Demo Web Server (Optional)

Test your Node.js installation by setting up a simple web server. Create a file http_server.js with basic code to display “Hello World!” and run it:

nano http_server.js 

and add the following content


const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Press “CTRL + O” to save changes and then press “CTRL + X” to close file and go back to terminal. Now use the following command to run above Node script:

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.

Conclusion

Installing Node.js on Debian systems is straightforward and allows users to leverage the power of Node.js for various applications. The process involves adding the official Node.js PPA, installing the software, and verifying the installation. Users also have the flexibility to choose between the latest or LTS versions based on their requirements. The optional step of creating a demo server can help in confirming the successful installation and functionality of Node.js.

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

Exit mobile version