Node.js is a popular runtime environment that allows you to run JavaScript on the server-side. In this tutorial, I will show you how to install Node.js 20 on Debian 12.
Step 1: Update your system
Before you begin, it’s always a good idea to update your system to make sure you have the latest versions of software packages. You can do this by running the following commands:
sudo apt update
sudo apt upgrade
Step 2: Install Node.js using the NodeSource repository
NodeSource provides an easy way to install Node.js on Debian-based systems. You can add the NodeSource repository to your system by running the following commands:
curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash -
This command will add the NodeSource repository to your system’s software sources.
Step 3: Install Node.js
After adding the NodeSource repository, you can install Node.js 20 by running the following command:
sudo apt install -y nodejs
This command will install Node.js 20 and npm, the package manager for Node.js.
Step 4: Verify the installation
To verify that Node.js has been installed correctly, run the following commands:
node -v
npm -v
These commands will display the version of Node.js and npm installed on your system.
Step 5: Create a simple Node.js application
To test that Node.js is working correctly, you can create a simple Node.js application. Create a new file called app.js
and add the following code:
const http = require('http');
http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello, Node.js!');
}).listen(3000);
console.log('Server running at http://localhost:3000/');
Save the file and run the following command to start the server:
node app.js
You should see the message Server running at http://localhost:3000/
in your terminal. Open a web browser and navigate to http://localhost:3000/
to see your Node.js application in action.
Congratulations! You have successfully installed Node.js 20 on Debian 12 and created a simple Node.js application. You can now start developing applications using Node.js on your Debian system.
Parabens
thanks!