How to install Node.js on Linux

By Angus Published 26 February 2026 Updated 27 February 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.
    Run sudo apt update to refresh the available packages from your configured repositories.
  2. Install Node.js and npm.
    Run sudo apt install -y nodejs npm to install both the runtime and package manager. The nodejs package provides the runtime whilst npm adds the package manager.
  3. Verify the installation.
    Check that both tools installed correctly by running node -v and npm -v. You should see version numbers printed for each command.

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 sudo apt-get update followed by sudo apt-get install -y ca-certificates curl gnupg to install the tools needed for adding the repository.
  2. Download the NodeSource GPG key.
    Create the keyrings directory with sudo mkdir -p /etc/apt/keyrings, then download and save the signing key using curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg. This verifies package authenticity during installation.
  3. Add the NodeSource repository.
    Set your target Node.js version with NODE_MAJOR=24, replacing 24 with your chosen major version number. Then run 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 to configure the repository. Check the Node.js release schedule to identify the current LTS version before running this command.
  4. Install Node.js.
    Update your package list with sudo apt-get update, then install Node.js using sudo apt-get install -y nodejs. This single package includes the Node.js runtime and npm.
  5. Verify the installation.
    Run node -v and npm -v to confirm both tools installed correctly.

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 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash 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.
  2. Reload your shell configuration.
    Run source ~/.bashrc to activate NVM in your current session without logging out.
  3. Install the latest Node.js release.
    Run nvm install node 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 20.
  4. Verify the installation.
    Run node -v and npm -v to confirm both tools installed correctly.

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