Install Node.js

How to install Node.js on a Linux server.

These instructions describe how to install Node.js on a Linux server using the prebuilt binaries from nodejs.org.

Posit recommends installing Node.js into a version-specific directory, such as /opt/nodejs/24.16.0, instead of using a system package manager. System package managers typically provide a single, shared version of Node.js and can replace it when you update system packages. Version-specific directories let you install multiple versions of Node.js side by side and upgrade each product or project on its own schedule.

Node.js is not Posit Software and is included in Third Party Materials (as defined in our EULA) and not covered under the Posit Support Agreement. If you download Node.js, you are agreeing to their license and acknowledge Posit is not responsible for Node.js and you are downloading Node.js at your sole risk.

Specify the Node.js version

Consult with your development team to determine which versions of Node.js they require.

Node.js publishes new major versions on a regular schedule, and only Long-Term Support (LTS) release lines receive extended maintenance. Posit recommends installing an Active LTS or Maintenance LTS version for production use. See the Node.js releases page for the status of each release line.

Once defined, set the environment variable to the first Node.js version they request:

Terminal
export NODE_VERSION="24.16.0"

Download and install Node.js

Detect the system architecture, then download and unpack the matching version of Node.js:

Terminal
if [ "$(uname -m)" = "aarch64" ]; then
  NODE_ARCH="arm64"
else
  NODE_ARCH="x64"
fi

sudo mkdir -p /opt/nodejs/${NODE_VERSION}

sudo curl -o nodejs.tar.xz -L \
    "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.xz"

sudo tar -xJf nodejs.tar.xz \
    -C "/opt/nodejs/${NODE_VERSION}" \
    --strip-components=1

sudo rm nodejs.tar.xz

This installs the node, npm, and npx executables into /opt/nodejs/${NODE_VERSION}/bin/.

Verify Node.js installation

Verify that Node.js is installed by running the following command:

Terminal
/opt/nodejs/"${NODE_VERSION}"/bin/node --version

(Optional) Install multiple versions of Node.js

To install multiple versions of Node.js on the same server, repeat the steps above, setting NODE_VERSION to a different version number each time.

This places different versions of Node.js in parallel directories under /opt/nodejs/, allowing products like Posit Connect to use multiple versions side by side.

Uninstall

To remove a version of Node.js, delete its installation directory:

Terminal
sudo rm -rf /opt/nodejs/${NODE_VERSION}

Additional resources

Configuring Node.js with Connect

Connect does not auto-discover Node.js installations from the PATH or any well-known directory. After completing the installation procedures above, configure Connect with the full path to each Node.js executable. See the following sections of the Posit Connect Admin Guide:

Installing Node.js

Refer to the Node.js download page for more information on installing Node.js, including all available versions and platforms.

Back to top