How to Install Node.js on Debian 12: A Step-by-Step Guide

Node.js is a powerful JavaScript runtime built on Chrome’s V8 JavaScript engine, and it’s used for developing server-side and networking applications. If you’re working with Debian 12 and looking to set up Node.js, this guide will walk you through the installation process, ensuring you’re ready to start developing your applications.

Step 1: Update Your System

Before installing any new software, it’s crucial to update your system to ensure all existing packages are up to date. Open your terminal and run the following commands:

sudo apt update
sudo apt upgrade -y

Step 2: Install Node.js

Debian 12’s default repositories include Node.js, but it might not always be the latest version. For the most recent release, it’s recommended to install Node.js using the NodeSource repository. First, you need to download the NodeSource setup script for Node.js:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash –

This command fetches the setup script for Node.js 18 and pipes it to bash for execution. Replace 18.x with a different version number if you need a specific version (check version lifecycle).

After adding the NodeSource repository, you can install Node.js:

sudo apt install -y nodejs

Step 3: Verify the Installation

Check the installed version of Node.js and npm (Node Package Manager) to ensure they are correctly installed:

node -v
npm -v

These commands should return the version numbers of Node.js and npm, respectively.

Step 4: Optionally Install Development Tools

To compile and install native addons from npm, you might need to install build tools:

sudo apt install -y build-essential

This command installs the essential compilers and libraries needed for compiling C/C++ based modules for Node.js.

Step 5: Test Your Node.js Setup

Create a simple “Hello, World!” application to test your Node.js installation. First, create a new file:

nano hello.js

Add the following JavaScript code to hello.js:

console.log(‘Hello, World!’);

Save and exit the editor, then run the application:

node hello.js

If Node.js is installed correctly, you should see “Hello, World!” printed in your terminal.

Conclusion

Congratulations! You have successfully installed Node.js on Debian 12. You’re now ready to start building your JavaScript applications or explore Node.js frameworks like Express for web development.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts