Skip to main content

How to Install Node.js on Manjaro

In this tutorial, we will walk you through the step-by-step process of installing Node.js on Manjaro, a user-friendly Linux distribution based on Arch Linux. Node.js is a powerful JavaScript runtime built on Chrome's V8 JavaScript engine, providing a platform for developing server-side and networking applications.

By the end of this tutorial, you will have Node.js installed on your Manjaro system and be ready to start building applications using JavaScript.

Prerequisites

Before we begin, make sure you have the following prerequisites:

  • A Manjaro Linux distribution installed on your machine.
  • Access to the internet to download the required packages.

Step 1: Update System Packages

To ensure that your Manjaro system is up to date, open the terminal and run the following command:

sudo pacman -Syu

This command will update your system packages to the latest versions.

Step 2: Install Node.js using the Package Manager

Manjaro provides an easy way to install Node.js using the package manager called pacman. Open the terminal and execute the following command:

sudo pacman -S nodejs npm

This command will install both Node.js and npm (Node Package Manager) on your system. npm is a powerful package manager that allows you to install, manage, and update Node.js packages and dependencies.

Step 3: Verify the Installation

After the installation is complete, you can verify if Node.js and npm are correctly installed by running the following commands:

node --version
npm --version

You should see the versions of Node.js and npm printed on the terminal, indicating that the installation was successful. For example:

v16.9.1
7.23.0

Step 4: Usage Examples

Now that Node.js is installed, you can start using it to run JavaScript code and build applications. Here are a few usage examples to get you started:

Example 1: Running a Simple JavaScript File

Create a new file called hello.js and open it in a text editor. Add the following code:

console.log("Hello, World!");

Save the file and open the terminal in the same directory. Run the following command:

node hello.js

You should see the output Hello, World! printed on the terminal.

Example 2: Creating a Simple HTTP Server

Create a new file called server.js and open it in a text editor. Add the following code:

const http = require('http');

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

server.listen(3000, 'localhost', () => {
console.log('Server running at http://localhost:3000/');
});

Save the file and open the terminal in the same directory. Run the following command:

node server.js

You should see the message Server running at http://localhost:3000/ printed on the terminal. This code creates a simple HTTP server that listens on port 3000 and responds with Hello, World! when accessed.

What to Watch Out For

During the installation process, there are a few things to keep in mind:

  • Ensure that you have a stable internet connection to download the required packages.
  • Double-check the commands you execute, especially when using sudo, as they have system-level permissions.
  • If you encounter any errors during the installation process, search for solutions specific to your system or consult the official Manjaro or Node.js documentation.

Congratulations! You have successfully installed Node.js on your Manjaro system. You can now start developing applications using JavaScript and leverage the power of Node.js and its vast ecosystem of packages. Happy coding!