Node.js is a cross-platform JavaScript runtime environment for building back-end and front-end applications. It is built on Chrome’s JavaScript, allowing 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 like traditional websites and back-end API services.

This post will show you how to install Node.js on Arch Linux.

Step 1 – 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 2 – Install Node.js for Arch Linux Repository

The Node.js package is included in the Arch Linux default repository by default. 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 3 – 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 4 – 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

This post 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!