Atlantic.Net Blog

How to Install and Use Node.js on Arch Linux

Node.js is a cross-platform JavaScript runtime environment used to build back-end and front-end applications. It is built on Chrome’s JavaScript which allows you to run JavaScript code on the server side. Node.js provides Node Package Manager to install and manage multiple node packages and dependencies. It is primarily deployed for non-blocking, event-driven servers, such as traditional websites and back-end API services.

In this post, we will show you how to install Node.js on Arch Linux.

Prerequisites

  • A fresh Arch Linux server on the Atlantic.Net Cloud Platform
  • A root password configured on your server

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Arch Linux as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Step 2 – Configure Repository

By default, the default repository is outdated in Arch Linux, so you will need to modify the default mirror list. You can do it by editing the mirrorlist configuration file:

nano  /etc/pacman.d/mirrorlist

Remove all lines and add the following lines:

## Score: 0.7, United States
Server = http://mirror.us.leaseweb.net/archlinux/$repo/os/$arch
## Score: 0.8, United States
Server = http://lug.mtu.edu/archlinux/$repo/os/$arch
Server = http://mirror.nl.leaseweb.net/archlinux/$repo/os/$arch
## Score: 0.9, United Kingdom
Server = http://mirror.bytemark.co.uk/archlinux/$repo/os/$arch
## Score: 1.5, United Kingdom
Server = http://mirrors.manchester.m247.com/arch-linux/$repo/os/$arch
Server = http://archlinux.dcc.fc.up.pt/$repo/os/$arch
## Score: 6.6, United States
Server = http://mirror.cs.pitt.edu/archlinux/$repo/os/$arch
## Score: 6.7, United States
Server = http://mirrors.acm.wpi.edu/archlinux/$repo/os/$arch
## Score: 6.8, United States
Server = http://ftp.osuosl.org/pub/archlinux/$repo/os/$arch
## Score: 7.1, India
Server = http://mirror.cse.iitk.ac.in/archlinux/$repo/os/$arch
## Score: 10.1, United States
Server = http://mirrors.xmission.com/archlinux/$repo/os/$arch

Save and close the file, then update all the package indexes with the following command:

pacman -Syu

Step 3 – Install Node.js for Arch Linux Repository

By default, the Node.js package is included in the Arch Linux default repository. You can install it by just running the following command:

pacman -S nodejs npm

Once Node.js is installed, you can verify the Node.js version with the following command:

node --version

You will get the following output:

v19.0.0

To check the NPM version, run the following command:

npm --version

You should see the following output:

8.19.2

Step 4 – Install NVM

NVM, also called “Node Version Manager,” is a tool used for installing and managing multiple Node.js versions on the system.

First, install the latest version of NVM with the following command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash

You should see the following command:

=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm

Next, run the following command to start using the NVM:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Next, verify the NVM version using the following command:

nvm --version

You should see the following output:

0.39.2

Step 5 – Install Node.js with NVM

To list all available Node.js versions, run the following command:

nvm list-remote

You will get a list of all versions in the following output:

        v17.8.0
        v17.9.0
        v17.9.1
        v18.0.0
        v18.1.0
        v18.2.0
        v18.3.0
        v18.4.0
        v18.5.0
        v18.6.0
        v18.7.0
        v18.8.0
        v18.9.0
        v18.9.1
       v18.10.0
       v18.11.0
       v18.12.0   (Latest LTS: Hydrogen)
        v19.0.0

To install the latest version of Node.js, run the following command:

nvm install node

You will get the following output:

Downloading and installing node v19.0.0...
Downloading https://nodejs.org/dist/v19.0.0/node-v19.0.0-linux-x64.tar.xz...
####################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v19.0.0 (npm v8.19.2)
Creating default alias: default -> node (-> v19.0.0)

To install the latest stable version of Node.js, run the following command:

nvm install --lts

You will get the following output:

Installing latest LTS version.
Downloading and installing node v18.12.0...
Downloading https://nodejs.org/dist/v18.12.0/node-v18.12.0-linux-x64.tar.xz...
####################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v18.12.0 (npm v8.19.2)

To install a specific Node.js version, run the following command:

nvm install 18.10.0

You should see the following output:

Downloading and installing node v18.10.0...
Downloading https://nodejs.org/dist/v18.10.0/node-v18.10.0-linux-x64.tar.xz...
####################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v18.10.0 (npm v8.19.2)

To list all installed Node.js versions, run the following command:

nvm ls

You should see the following output:

->     v18.10.0
       v18.12.0
        v19.0.0
         system
default -> node (-> v19.0.0)

To change the default Node.js version to 19.0.0, run the following command:

nvm use 19.0.0

You will get the following output:

Now using node v19.0.0 (npm v8.19.2)

Conclusion

In this post, we explained different ways to install Node.js on Arch Linux. You can now choose your preferred method depending on your requirements. We recommend using the NVM method as it gives you more flexibility for adding and removing different Node.js versions on a per-user basis. Try Node.js on dedicated servers from Atlantic.Net!

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year