- Vrealmatic
- Ubuntu Server
- Node.js
Node.js on Ubuntu Server
How to install and manage Node.js on Ubuntu Server?

How to Install Node.js on Ubuntu?
There are 3 ways of installing Node.js on Ubuntu Server.
Installing Node.js with Apt from the Default Repositories
Node.js is a part of default repositories of Ubuntu Server and thus may be installed through Apt from default repositories. The binaries are installed system-wide (owned by root), which is standard. What matters for security is that your Node.js applications do not run as root – run them under a dedicated unprivileged user (see user management).
Be aware that the default repositories contain older Node.js versions - e.g. Ubuntu 24.04 ships Node.js 18, which reached end of life in April 2025. For current LTS versions (Node.js 24 at the time of writing) use NVM or the NodeSource repository.
sudo apt update- update the package lists for upgrades and updates on your Linux systemsudo apt install nodejs- install Node.js through the apt package managernode -v- check installed node version (verification, than the node.js was installed)- Run your application under a dedicated unprivileged user, not as
root
Installing Node.js with Apt Using the NodeSource Repository
NodeSource maintains Apt repositories with current Node.js versions. Installation stays system-wide via Apt (updates come with apt upgrade), but you get a current LTS release instead of the older version from the Ubuntu repositories.
- Download and run the setup script for the required major version (e.g. 24 LTS):
curl -fsSL https://deb.nodesource.com/setup_24.x -o nodesource_setup.sh sudo -E bash nodesource_setup.shBefore running a downloaded script with
sudo, review its content (less nodesource_setup.sh). sudo apt install -y nodejs- install Node.js (npm is included)node -v- verify the installed version
Installing Node Using the Node Version Manager (Recommended)
Node Version Manager (NVM) is a piece of shell code that allows you to easily install and maintain many different independent versions of Node.js, and their associated Node packages.
Before start, Check latest verision of NVM on GitHub. Then, use the last version in the guide below.
NodeJs may be installed under any account, see below:
- Check NVM code
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh - Install NVM code.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bashThe NVM is installed with permissions of a user that processing that request (you). NVM is installed to the user's home directory (
~/.nvm) and its loader is added to the~/.bashrcfile. source ~/.bashrc- source/reload the script for the option to use itnvm list-remote --lts- check available LTS versions of Node.jsnvm install --lts- install the current LTS version of Node.js (or a specific one, e.g.nvm install v24.13.1). Node.js is installed with permissions of a user that processing that request (you)node -v- show currently active version
As of Node.js is installed for user account only, it is known under node -v of current user, but not under any other user nor sudo node -v. There are 2 ways to make node command (access to teh Node.js client) available also for other users:
- Symlink
There's possible to create a symlink from
/usr/local/bin/nodeto the node client in the user's account$NVM_DIR/versions/node/$(nvm version)/bin/nodesudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/node" "/usr/local/bin/node" - Environment variable with adding to user group (recommended)
When creating native services, you can add there a
Environmentvariable referring to the Node.js client, see[Unit] Description="My service" Wants=network-online.target After=network-online.target [Service] User=<serviceUser> Group=<serviceUser> Type=simple Restart=always RestartSec=5 WorkingDirectory=/directory/to/service/client Environment="PATH=/home/<userNameWithNodeClient>/.nvm/versions/node/v24.13.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ExecStart=...Note, to make the
nodeaccessible, the <serviceUser> must be added into the <userNameWithNodeClient> group.sudo usermod -aG userNameWithNodeClient serviceUser
Installing NodeJS under system account
- Create user and directory
sudo useradd --system --shell /bin/bash --home /srv/nodejs nodejsusrsudo mkdir -p /srv/nodejssudo chown nodejsusr:nodejsusr /srv/nodejs - Switch at
nodejsusrsudo -i -u nodejsusr - Install and enable NVM
Create bashsrccurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
Open the file with following contenttouch ~/.bashrc && nano ~/.bashrc
Reload shell profileexport NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Check installed nvm versionsource ~/.bashrcnvm --version - Install Node js
nvm list-remote- check available Node.js versionsnvm install --lts- install the current LTS version of Node.js (or a specific one, e.g.nvm install v24.13.1).
Check installed npm versionnode -vnpm -v - Retrun back at standard user
exit - Set shared access for nodejs and npm
sudo ln -sf "$(ls -d /srv/nodejs/.nvm/versions/node/*/bin/node | sort -V | tail -n1)" /usr/local/bin/nodesudo ln -sf "$(ls -d /srv/nodejs/.nvm/versions/node/*/bin/npm | sort -V | tail -n1)" /usr/local/bin/npm
Upgrading / Downgrading NodeJS under system account
- Sign in as
nodejsusrand relaod bashrcsudo -i -u nodejsusr source ~/.bashrc - Install new Node.js version with NVM
nvm install vXX.X.X nvm use XX.X.X nvm alias default XX.X.X - Update Symlinks
Symlinks are visible through
ls -lh /usr/local/bin.sudo unlink /usr/local/bin/node sudo unlink /usr/local/bin/npmCreate new symlinks at latest version
sudo ln -sf "$(ls -d /srv/nodejs/.nvm/versions/node/*/bin/node | sort -V | tail -n1)" /usr/local/bin/node sudo ln -sf "$(ls -d /srv/nodejs/.nvm/versions/node/*/bin/npm | sort -V | tail -n1)" /usr/local/bin/npm
Managing building packages tools
Note: Corepack (used below for yarn and pnpm) is bundled with Node.js up to v24 LTS. Since Node.js 25 it is no longer part of the Node.js distribution - on newer versions install it first with npm install -g corepack, then use corepack enable as described below.
- Log in to
nodejsusrand
Reload bashrcsudo -i -u nodejsusr
get corepack yarnsource ~/.bashrcwhich yarn - Return back at standard user
exit - Create the symlink to corepack path
sudo ln -s /srv/nodejs/.nvm/versions/node/vXX.X.X/bin/yarn /usr/local/bin/yarn - Check corepack availability
yarn --version
- Log in to
nodejsusrand
Reload bashrcsudo -i -u nodejsusr
enable corepacksource ~/.bashrccorepack enable - Prepare pnpm
verify:corepack prepare pnpm@latest --activatepnpm --versionwhich pnpm - Create the symlink to corepack path
sudo ln -s /srv/nodejs/.nvm/versions/node/vXX.X.X/bin/pnpm /usr/local/bin/pnpm - Return to standard user:
exitCheck corepack availabilitypnpm --version
Useful commands
which node/which corepackCheck nodejs / corepack locationnvm ls- Listing Installed NodeJS Instancesnpm -v- get version of NPM (When installing a Node.js instance, nvm also installs a compatible npm version.)
Installing next versions
nvm list-remote- check available Node.js versionsnvm install vXX.XX.X- install requested version of Node.js. After that, this new version will begin default running node version on Ubuntu Server. The previous version is still available, seenvm ls.
Switching to selected node version
nvm use XX.X.X
Set default Node.js version
nvm alias default XX.X.X
Uninstalling useless versions
nvm uninstall XX.X.X
Need a secure server setup?
We design, secure and document networks and servers.