How to Install Node.js on Arch Linux

When you install Node.js on Arch Linux, you get a JavaScript runtime that powers backend APIs, real-time applications, command-line tools, and build systems for modern web development. Common use cases include running Express or Fastify servers, building frontends with Vite or Webpack, automating tasks with scripts, and managing microservices. Arch Linux provides Node.js directly in the official repositories alongside multiple LTS releases, giving you the flexibility to match your project’s requirements without adding third-party sources.

This guide walks through installing Node.js on Arch Linux from the official repositories, choosing between the current release and LTS versions, configuring npm for safe global package installation, and managing multiple Node.js versions with nvm. By the end, you will have a working Node.js development environment with npm configured to install global packages without root privileges.

Update Arch Linux Before Installation

Synchronize package databases and upgrade installed packages before installing new software. Arch Linux is a rolling release distribution, so running a full upgrade first prevents dependency conflicts:

sudo pacman -Syu

This guide uses sudo for commands that need root privileges. If your user is not in the sudoers file yet, run the commands as root or follow the guide on how to add and manage sudo users on Arch Linux.

Install Node.js on Arch Linux

The official Arch Linux repositories provide multiple Node.js packages: the current release with the latest features, and several LTS (Long Term Support) releases for projects that need stability and extended maintenance windows.

Choose a Node.js Version

Arch Linux maintains the current Node.js release alongside active LTS versions. Each LTS release has a codename and follows a predictable support schedule from the Node.js project.

PackageVersionChannelBest For
nodejs25.xCurrentDevelopers wanting the latest features and APIs
nodejs-lts-krypton24.xActive LTSMost users; best balance of features and stability
nodejs-lts-jod22.xMaintenance LTSProjects requiring a proven, widely tested release
nodejs-lts-iron20.xMaintenance LTSLegacy projects with specific version requirements

For most users, the active LTS release is recommended because it receives new features along with security updates and has the longest remaining support window. The current release (odd-numbered) does not enter LTS and reaches end-of-life sooner.

These packages conflict with each other since they all provide the node binary. Pacman will prompt you to remove the existing Node.js package when switching to a different version.

Install Node.js Current Release

Install the latest current release of Node.js:

sudo pacman -S nodejs npm

The nodejs package provides the Node.js runtime and the node binary. The npm package installs the Node Package Manager separately since Arch Linux does not bundle npm with the Node.js runtime.

Install Node.js LTS Release

Install the active LTS release for production-oriented stability:

sudo pacman -S nodejs-lts-krypton npm

Replace nodejs-lts-krypton with nodejs-lts-jod or nodejs-lts-iron if your project requires an older LTS version.

Verify Node.js Installation

Confirm Node.js and npm are installed and accessible:

node --version
npm --version

Expected output (versions reflect the package you installed):

v24.13.0
11.8.0

Since Arch uses a rolling release model, Node.js updates arrive automatically through regular system upgrades with sudo pacman -Syu.

Configure npm Global Prefix on Arch Linux

By default, npm installs global packages to /usr/lib/node_modules/, which requires root access and conflicts with pacman’s file tracking. Redirecting global installs to a user-owned directory avoids permission issues and keeps npm packages separate from system-managed files.

Set the User-Local Prefix

Configure npm to install global packages under ~/.local and add the binary directory to your PATH. Add these lines to your shell profile:

echo 'export npm_config_prefix="$HOME/.local"' >> ~/.bashrc
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

If you use Zsh instead of Bash, add the export lines to ~/.zshrc instead.

The npm_config_prefix environment variable redirects all global npm operations to ~/.local/. Binaries from globally installed packages land in ~/.local/bin/, which the PATH addition makes available as commands.

Verify the Prefix Configuration

Confirm npm uses the new prefix:

npm config get prefix
/home/username/.local

Test a Global Package Install

Install a lightweight package to verify global installations work without sudo:

npm install -g http-server

Verify the binary is accessible:

command -v http-server
/home/username/.local/bin/http-server

If the command returns no output, verify that ~/.local/bin is in your PATH by running echo $PATH.

Never run sudo npm install -g on Arch Linux. Installing npm packages as root writes files outside pacman’s control, which can cause conflicts during system upgrades and break package integrity checks.

Manage Multiple Node.js Versions with nvm on Arch Linux

The Node Version Manager (nvm) lets you install and switch between multiple Node.js versions in your home directory. This is useful for testing applications across Node.js releases, matching a project’s required version, or running different versions for separate projects. Arch Linux provides nvm in the official repositories.

Install nvm

Install nvm from the official repositories:

sudo pacman -S nvm

Load nvm into your current shell session by sourcing its initialization script. Add this line to your shell configuration so nvm loads automatically on future sessions:

echo 'source /usr/share/nvm/init-nvm.sh' >> ~/.bashrc
source ~/.bashrc

If you use Zsh, add the source line to ~/.zshrc instead.

Verify nvm loaded correctly:

nvm --version
0.40.4

Install Node.js Versions with nvm

List available Node.js LTS versions:

nvm ls-remote --lts | tail -20

Install the latest LTS version:

nvm install --lts

Install a specific version when a project requires it:

nvm install 22

This installs the latest patch release of the Node.js 22.x line.

Switch Between Node.js Versions

List locally installed versions:

nvm ls

Example output showing multiple installed versions (your output will include additional alias entries for older LTS codenames):

->     v22.22.0
       v24.13.0
default -> lts/* (-> v24.13.0)
node -> stable (-> v24.13.0) (default)
stable -> 24.13 (-> v24.13.0) (default)
lts/* -> lts/krypton (-> v24.13.0)
lts/iron -> v20.20.0 (-> N/A)
lts/jod -> v22.22.0
lts/krypton -> v24.13.0

Switch to a different version for the current session:

nvm use 24
Now using node v24.13.0 (npm v11.6.2)

Set a default version that loads automatically in every new shell:

nvm alias default 24

Use Per-Project Node.js Versions

Projects often specify their required Node.js version in a .nvmrc file at the repository root. Create one for your project:

echo "22" > .nvmrc

When you enter a directory containing a .nvmrc file, run nvm use to switch to the specified version:

nvm use
Found '/home/username/project/.nvmrc' with version <22>
Now using node v22.22.0 (npm v10.9.4)

Node.js versions installed through nvm are entirely separate from the system nodejs package installed via pacman. They coexist without conflict because nvm installs to ~/.nvm/ and manages PATH precedence through its shell initialization script.

Test Your Node.js Installation on Arch Linux

Verify that Node.js can execute JavaScript and that npm can initialize projects by running a quick test.

Run a Quick JavaScript Test

Execute a JavaScript expression directly from the terminal:

node -e "console.log('Node.js ' + process.version + ' is working on Arch Linux')"
Node.js v24.13.0 is working on Arch Linux

Create and Run a Test Script

Create a file named test.js:

nano test.js

Add the following JavaScript code:

const http = require('http');

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello from Node.js on Arch Linux\n');
});

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

Save the file with Ctrl+O, press Enter, then exit with Ctrl+X.

Run the test server:

node test.js
Server running at http://localhost:3000/

Open a second terminal and test the server:

curl http://localhost:3000
Hello from Node.js on Arch Linux

Press Ctrl+C in the first terminal to stop the server. Remove the test file when finished:

rm test.js

Initialize a New npm Project

Verify npm can create and manage projects:

mkdir ~/test-project && cd ~/test-project
npm init -y

Expected output:

Wrote to /home/username/test-project/package.json:

{
  "name": "test-project",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": ""
}

The -y flag accepts all defaults, creating a package.json without interactive prompts. Clean up the test project:

cd ~ && rm -rf ~/test-project

Install Node.js Native Addon Build Dependencies on Arch Linux

Some npm packages include native C/C++ addons that compile during installation using node-gyp. These packages require a C++ compiler, Make, and Python. Install the build tools if you encounter compilation errors during npm install:

sudo pacman -S base-devel python

The base-devel group includes gcc, make, and other compilation tools. The python package provides the Python interpreter that node-gyp uses during the build process. Common packages that require native compilation include bcrypt, sharp, sqlite3 (see the guide to install SQLite on Arch Linux for the system library), and canvas.

Troubleshoot Node.js on Arch Linux

npm Permission Errors on Global Install

Error: Running npm install -g fails with “EACCES: permission denied”.

npm error code EACCES
npm error syscall mkdir
npm error path /usr/lib/node_modules/package-name
npm error errno -13

Cause: npm is trying to write to the system directory /usr/lib/node_modules/, which requires root access.

Fix: Configure a user-local prefix as described in the npm configuration section above:

echo 'export npm_config_prefix="$HOME/.local"' >> ~/.bashrc
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

After sourcing, retry the global install without sudo.

Node.js Version Conflicts Between pacman and nvm

Error: Running node --version shows the pacman-installed version even after nvm use.

Cause: The nvm initialization script is not loaded, so the system node binary takes precedence.

Diagnostic: Check which node binary is active:

command -v node

If it returns /usr/bin/node instead of a path under ~/.nvm/, nvm is not active in the current session.

Fix: Ensure the nvm initialization line exists in your shell configuration and source it:

grep 'init-nvm.sh' ~/.bashrc

If no output appears, add the initialization line:

echo 'source /usr/share/nvm/init-nvm.sh' >> ~/.bashrc
source ~/.bashrc

node-gyp Build Failures

Error: npm install fails with node-gyp errors referencing missing Python, make, or compiler:

gyp ERR! find Python
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Python installation to use

Fix: Install the required build dependencies:

sudo pacman -S base-devel python

If the error persists after installing dependencies, clear the npm cache and retry:

npm cache clean --force
npm install

Module Not Found After Global Install

Error: A globally installed package returns “command not found” when run.

Diagnostic: Check where npm installed the package:

npm list -g --depth=0

Verify the npm prefix and PATH are configured correctly:

npm config get prefix
echo $PATH

Fix: Ensure the prefix’s bin directory appears in your PATH. If npm config get prefix returns /home/username/.local, then /home/username/.local/bin must be in your PATH variable.

Remove Node.js from Arch Linux

If you no longer need Node.js, remove it and clean up related configuration.

Remove pacman-Installed Node.js

Remove Node.js, npm, and orphaned dependencies:

sudo pacman -Rns nodejs npm

If you installed an LTS version, replace nodejs with the LTS package name:

sudo pacman -Rns nodejs-lts-krypton npm

The -Rns flags remove the packages (-R), orphaned dependencies (-s), and configuration backup files (-n).

If you installed nvm via pacman, remove it as well:

sudo pacman -Rns nvm

Remove nvm Data and Global npm Packages

The following commands permanently delete all nvm-managed Node.js versions and globally installed npm packages. Back up any project dependencies before proceeding.

Remove nvm-installed Node.js versions and data:

rm -rf ~/.nvm

Remove globally installed npm packages, their binaries, and the npm cache:

rm -rf ~/.local/lib/node_modules
find ~/.local/bin -lname '*/node_modules/*' -delete 2>/dev/null
rm -rf ~/.npm

The find command removes all symlinks in ~/.local/bin/ that point to npm-installed packages, catching every globally installed binary rather than only specific ones.

Clean Up Shell Configuration

Remove the configuration lines added during this guide from ~/.bashrc (or ~/.zshrc):

  • The export npm_config_prefix="$HOME/.local" line
  • The export PATH="$HOME/.local/bin:$PATH" line
  • The source /usr/share/nvm/init-nvm.sh line

Open a new terminal or run source ~/.bashrc for the changes to take effect.

Verify Removal

Confirm Node.js is no longer installed:

pacman -Qi nodejs

Expected output:

error: package 'nodejs' was not found

Frequently Asked Questions

Is npm included with the Node.js package on Arch Linux?

No. Unlike many other distributions, Arch Linux packages npm separately from Node.js. You must install both nodejs (or a nodejs-lts variant) and npm as separate packages with pacman. This separation gives you control over which components you install.

How do I switch between Node.js LTS versions on Arch Linux?

With pacman, install a different LTS package such as sudo pacman -S nodejs-lts-jod. Pacman will prompt you to remove the currently installed Node.js package since they conflict. With nvm, install multiple versions (nvm install 22 and nvm install 24) and switch between them using nvm use 22 or nvm use 24 without removing anything.

Does nvm conflict with the system Node.js on Arch Linux?

No. nvm installs Node.js versions to ~/.nvm/ and manages PATH precedence through its shell initialization script. The pacman-installed Node.js in /usr/bin/ remains untouched. You can switch between nvm-managed versions and the system version with nvm use system.

How do I update Node.js on Arch Linux?

For pacman-installed Node.js, run sudo pacman -Syu to update all system packages including Node.js. For nvm-managed versions, run nvm install <version> to install the latest patch release of a major version, then nvm alias default <version> to make it the default.

Node.js Resources and Related Arch Linux Guides

For Arch Linux-specific configuration details and advanced topics, the Arch Wiki Node.js page covers supplemental package management considerations, alternative installation methods, and community recommendations.

If you plan to use Node.js with a database backend, see the guides for PostgreSQL on Arch Linux or MariaDB on Arch Linux. For containerizing Node.js applications, the Docker on Arch Linux guide covers container setup and multi-container workflows with Docker Compose. To secure a production Node.js server over the network, see the guide to install and configure OpenSSH on Arch Linux.

Additional resources for Node.js development:

Conclusion

You now have Node.js installed on Arch Linux with npm configured for safe global package installation and nvm available for managing multiple Node.js versions across projects. For production Node.js applications, secure your server with UFW or firewalld to control access to application ports, and deploy through Docker containers for reproducible environments. For advanced npm configuration, package publishing, and workspace management, refer to the npm documentation.

Leave a Comment

Let us know you are human: