Intermediate Standard

How to install Node.js on Linux

By Angus Published 26 February 2026 Updated 14 May 2026 5 min read

Node.js executes JavaScript code outside the browser, turning it into a language for building servers, command-line utilities and backend services. Installing Node.js on your Linux server gives you the node runtime for executing code and npm for managing third-party packages.

You will install Node.js using one of three approaches depending on your requirements. The default package manager installs a stable version quickly. NodeSource repositories provide current releases with security updates. NVM lets you run multiple Node.js versions side by side for testing across different releases.

Before you begin

  • You need SSH access to your Linux server.
  • We recommend running sudo apt update before installing new packages.

Install Node.js from default repositories

Your Linux distribution includes Node.js in its standard package repositories. This method installs a tested, stable version that may be several releases behind the current upstream version. Use this approach when you need Node.js running quickly and do not require the latest features.

  1. Update your package list.
    Use the following command to refresh the available packages from currently configured repositories:
sudo apt update
  1. Install Node.js and npm.
    Run the following command to install the runtime and package manager. The nodejs package provides the runtime whilst npm adds the package manager.
sudo apt install -y nodejs npm
  1. Verify the installation.
    Check that tools installed correctly by running the following commands. You should see version numbers printed for each.
node -v
npm -v

Your Node.js installation now works for running applications and installing dependencies. This method suits production environments where stability matters more than having the absolute latest version.

Install Node.js from NodeSource repositories

NodeSource maintains official Node.js packages for Debian and Ubuntu that track upstream releases closely. This method gives you access to recent Node.js versions including current and Long Term Support (LTS) lines. Use NodeSource when your application requires features or security patches from newer releases.

  1. Install required dependencies.
    Run the following commands to install the tools needed for adding the repository.
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
  1. Download the NodeSource GPG key.
    Create the keyrings directory, then download and save the signing key using the following commands. This verifies package authenticity during installation.
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
  1. Add the NodeSource repository.
    Set your target Node.js version by running the following command, replacing 24 with your chosen major version number. Check the Node.js release schedule to identify the current LTS version before running this command.
NODE_MAJOR=24
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
  1. Install Node.js.
    Update your package list, then install Node.js using the following commands. The single nodejs package includes the Node.js runtime and npm.
sudo apt-get update
sudo apt-get install -y nodejs
  1. Verify the installation.
    Run the following commands to confirm tools installed correctly.
node -v
npm -v

NodeSource packages receive regular updates that track official Node.js releases. Your server will receive security patches and minor version updates through the standard apt upgrade process. This method balances currency with the convenience of system package management.

Install Node.js using NVM

Node Version Manager (NVM) installs Node.js versions into your home directory rather than system-wide locations. This lets you switch between releases without affecting other users or requiring root access after the initial setup. NVM works well on development servers where you need to test code against multiple Node.js versions.

  1. Download and run the NVM installation script.
    Run the following command to install NVM. Check the NVM releases page for the latest version number and update the URL accordingly. The script modifies your shell profile to load NVM automatically.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
  1. Reload your shell configuration.
    Run the following command to activate NVM in your current session without logging out.
source ~/.bashrc
  1. Install the latest Node.js release.
    Run the following command to fetch and install the most recent version. The keyword node tells NVM to fetch the latest release. To install a specific version, specify the major version number instead.
nvm install node
nvm install 20
  1. Verify the installation.
    Run the following commands to confirm tools installed correctly.
node -v
npm -v

NVM maintains separate npm installations for each Node.js version, preventing dependency conflicts between projects. Switch between installed versions with nvm use 18 or set a default version using nvm alias default 20. Each version remains isolated in your home directory at ~/.nvm/versions/node/.

Wrapping up

Your Linux server now runs Node.js and npm for building JavaScript applications outside the browser. You installed using the default package manager for stability, NodeSource repositories for current releases or NVM for version flexibility. The node command executes JavaScript files whilst npm handles package installation.

Test your installation by creating a file called hello.js containing console.log('Node.js installed'); and running node hello.js. You should see your message printed to the terminal.

Need more power?

Get scalable resources with our VPS hosting with root access and optional software.

Get VPS Hosting

Starting something new?

Perfect for websites and small businesses unlimited bandwidth with cPanel hosting.

Get cPanel Hosting