Verified guide
This guide was verified by creating a cloud server and running every command in it, from start to finish, exactly as written.
- OS
- Ubuntu 24.04.5 LTS · x86_64
- Installed version
- Node.js 24.22.0 (npm 11.19.1), nvm 0.40.8
- Test server
- DigitalOcean · 1 vCPU / 1 GB RAM / 25 GB SSD (s-1vcpu-1gb, sgp1)
- Last checked
- 2026-10-15
This guide contains affiliate links. If you sign up through them, Codesand may earn a commission. This doesn't affect the content or our assessments.
This guide installs the Node.js LTS release on an Ubuntu 24.04 server with nvm, then covers checking node and npm, installing and switching between versions, changing the default version, fixing the "Command 'nvm' not found" and "sudo: node: command not found" errors, and removing everything cleanly.
1. Requirements
- One Ubuntu 24.04 LTS server or PC
- A regular user account with
sudoprivileges - An internet connection (files are downloaded from nodejs.org and GitHub)
If you don't have a server, try the smallest DigitalOcean Droplet (1 vCPU, 1 GB). It is enough to install and run Node.js. Every step in this guide was verified on a Droplet (1 vCPU, 1 GB memory, 25 GB SSD, Ubuntu 24.04, Singapore) using a regular user account with sudo privileges.
2. Check the state before installing
If Node.js is not installed, you see a message that the node command cannot be found, along with a suggestion to install it with apt.
node -vCommand 'node' not found, but can be installed with:
sudo apt install nodejsLet's check which version you would get by following that suggestion and installing with apt. First, update the package list. The beginning of the output (the Hit and Get lines) is omitted.
sudo apt updateFetched 12.1 MB in 5s (2416 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
54 packages can be upgraded. Run 'apt list --upgradable' to see them.Candidate is the version that apt install nodejs would install. The default Ubuntu 24.04 repository ships Node.js 18.
apt-cache policy nodejsnodejs:
Installed: (none)
Candidate: 18.19.1+dfsg-6ubuntu5
Version table:
18.19.1+dfsg-6ubuntu5 500
500 http://sgp1.clouds.archive.ubuntu.com/ubuntu noble/universe amd64 PackagesNode.js 18 reached end of life in April 2025, and the latest LTS on the day this guide was verified was 24. This guide installs Node.js with nvm (Node Version Manager) instead of apt. nvm downloads the official files from nodejs.org into your user folder (~/.nvm), so it does not need sudo, and you can keep several versions installed and switch between them with a single command.
3. Install nvm
Download and run the nvm install script. This guide installs nvm 0.40.8, the latest version on the day it was verified. curl -o- prints the downloaded content to the screen instead of saving it to a file, and | bash passes that content to bash to run it right away.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.8/install.sh | bash=> Downloading nvm from git to '/home/devuser/.nvm'
=> Cloning into '/home/devuser/.nvm'...
…
=> Compressing and cleaning up git repository
=> Appending nvm source string to /home/devuser/.bashrc
=> Appending bash_completion source string to /home/devuser/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export 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_completionnvm is installed in the ~/.nvm folder, and three lines that load nvm every time you open a terminal are appended to the end of ~/.bashrc.
4. Verify the nvm installation
If you run nvm right away in the terminal where you installed it, you get a message that the command cannot be found. This is because the terminal was opened before the three lines were added to ~/.bashrc.
nvm --versionCommand 'nvm' not found, did you mean:
command 'nm' from deb binutils (2.42-4ubuntu2.10)
command 'num' from deb quickcal (2.4-1)
command 'nam' from deb nam (1.15-6)
…
Try: sudo apt install <deb name>Do not install the suggested packages. Close and reopen the terminal (for SSH, disconnect and reconnect), or reload ~/.bashrc with the command below. It prints nothing.
source ~/.bashrcnvm --version0.40.85. Install the Node.js LTS release
LTS is the stable release line with long-term support. Install LTS unless you have a specific reason not to. With --lts, nvm finds and installs the latest LTS version.
nvm install --ltsInstalling latest LTS version.
Downloading and installing node v24.22.0...
Downloading https://nodejs.org/dist/v24.22.0/node-v24.22.0-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v24.22.0 (npm v11.19.1)
Creating default alias: default -> lts/* (-> v24.22.0 *)The first version you install becomes the default version (default), which is used every time you open a new terminal. Check that node, npm, and npx run.
node -vv24.22.0npm -v11.19.1npx -v11.19.1You can also check where the node binary that runs is located. It is installed in the .nvm folder inside your user folder.
which node/home/devuser/.nvm/versions/node/v24.22.0/bin/node6. Install and switch to another version
Use nvm ls-remote to see which versions you can install. Adding a number shows only that major version, and tail -n 3 shows only the last three lines.
nvm ls-remote 22 | tail -n 3 v22.23.1 (LTS: Jod)
v22.23.2 (LTS: Jod)
v22.23.3 (Latest LTS: Jod)Install Node.js 22 as well. If you give only the major version, the latest release of that major version is installed, and the current terminal switches to it right away.
nvm install 22Downloading and installing node v22.23.3...
Downloading https://nodejs.org/dist/v22.23.3/node-v22.23.3-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v22.23.3 (npm v10.9.9)node -vv22.23.3Check the list of installed versions. The one marked with -> is the version used in the current terminal, and default is the version used when you open a new terminal. The lts/… lines that follow are a list of version names, so they are omitted.
nvm ls-> v22.23.3
v24.22.0
default -> lts/* (-> v24.22.0)nvm install 22 changed only that terminal. When you open a new terminal, the default version v24.22.0 is used again.
node -vv24.22.0To switch only the current terminal to another version, use nvm use.
nvm use 22Now using node v22.23.3 (npm v10.9.9)node -vv22.23.3To keep using 22 in new terminals too, change the default version.
nvm alias default 22default -> 22 (-> v22.23.3)Open a new terminal, and 22 is used.
node -vv22.23.3Set the default version back to 24, and switch the current terminal to the default version as well.
nvm alias default 24default -> 24 (-> v24.22.0)nvm use defaultNow using node v24.22.0 (npm v11.19.1)7. Run a first project with npm
To confirm the installation works, install and run an npm package. Create a hello-node folder under your home folder and move into it. npm init -y creates a package.json file with default values without asking any questions.
mkdir hello-node && cd hello-node
npm init -yWrote to /home/devuser/hello-node/package.json:
{
"name": "hello-node",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs"
}Install the dayjs package, which handles dates.
npm install dayjsadded 1 package, and audited 2 packages in 1s
found 0 vulnerabilitiesCreate an index.js file that uses dayjs and run it. The first line creates the file from the text in quotes, so it prints nothing.
echo "const dayjs = require('dayjs'); console.log('Hello Node.js', process.version, dayjs().format('YYYY-MM-DD'));" > index.js
node index.jsHello Node.js v24.22.0 2026-10-15If the Node.js version and today's date are shown, both Node.js and npm are working.
8. Troubleshooting
Command 'nvm' not found, did you mean:
This means you ran it in a terminal that was open before nvm was installed. That terminal has not read the three lines added to ~/.bashrc during installation. Close and reopen the terminal, or run source ~/.bashrc. The packages listed with the message are other programs with similar names and have nothing to do with nvm, so do not install them. If a new terminal shows the same message, check with tail -n 3 ~/.bashrc that the three NVM_DIR lines are there.
sudo: node: command not found
Node.js installed with nvm lives in your user folder (~/.nvm), but sudo replaces the command search path (PATH) with the system default path, so it cannot find this folder. Run node and npm without sudo.
sudo node -vsudo: node: command not foundCommand 'node' not found, but can be installed with:
This means Node.js is not installed, or the terminal has not loaded nvm. First check that nvm runs with nvm --version. If nvm cannot be found either, open a new terminal as described above. If nvm runs but you still see this message, check with nvm ls that a version is installed. Do not run the suggested sudo apt install nodejs, because it installs Node.js 18 from the Ubuntu repository.
nvm: Cannot uninstall currently-active node version
You cannot uninstall the version that the current terminal is using. Switch to another version with nvm use, then uninstall it. You can see the actual message in step 9.
9. Uninstall
Remove a single Node.js version
To remove just one of the versions installed with nvm, use nvm uninstall. First, go back to your home folder. The version you are currently using cannot be removed.
cd ~
nvm uninstall 24nvm: Cannot uninstall currently-active node version, v24.22.0 (inferred from 24).Version 22, which is not in use, is removed.
nvm uninstall 22Uninstalled node v22.23.3nvm ls-> v24.22.0
default -> 24 (-> v24.22.0)Remove nvm and all Node.js versions
nvm and every Node.js version installed with it live in the ~/.nvm folder. First, check the three lines added to ~/.bashrc in step 3.
tail -n 3 ~/.bashrcexport 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_completionDelete the ~/.nvm folder, the ~/.npm folder where npm keeps downloaded packages, and the practice ~/hello-node folder from step 7. Then delete the three lines containing NVM_DIR from ~/.bashrc. sed -i edits the file in place, and /NVM_DIR/d deletes the lines that contain NVM_DIR. Neither command prints anything.
rm -rf ~/.nvm ~/.npm ~/hello-node
sed -i '/NVM_DIR/d' ~/.bashrcClose and reopen the terminal to check. If both node and nvm report that the command cannot be found, everything has been removed.
node -vCommand 'node' not found, but can be installed with:
sudo apt install nodejsnvm --versionCommand 'nvm' not found, did you mean:
command 'nsm' from deb linuxptp (4.0-1ubuntu1.1)
command 'nam' from deb nam (1.15-6)
command 'nm' from deb binutils (2.42-4ubuntu2.10)
…
Try: sudo apt install <deb name>Try it yourself
No server yet? You can spin up an Ubuntu server in a few minutes with one of these providers. We verified this guide on DigitalOcean.
Was this guide helpful? Let us know if anything is wrong or out of date.
Request a correction