Logic Encoder Blog

Install Node.js on Ubuntu with nvm: Versions and Fixes

Sep 11, 2025 Logic Encoder 5 min read

Install Node.js on Ubuntu with nvm, one version per project

nvm (Node Version Manager) installs Node.js into your home directory and lets each shell switch between versions. It is a good fit for a development machine where projects need different Node.js releases. Install it as your normal user, not with sudo.

In this guide
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.41.0/install.sh | bash
# open a new terminal, then:
nvm install --lts
node --version
npm --version

The version in that address (v0.41.0) is the release named in the nvm README in November 2026. Check the README for the current one before you copy the command.

Why not simply apt install nodejs

The Node.js packages in Ubuntu’s own repositories are far behind the upstream project:

Ubuntu releasenodejs packageUpstream status of that line
22.04 (jammy)12.22.9End of life
24.04 (noble)18.19.1End of life since 30 April 2025

The distribution package can still be right when other Ubuntu packages depend on it. For application development you normally want a release line that the Node.js project still maintains.

Which Node.js line to choose

Status in November 2026, from the Node.js release schedule:

LineStatusMaintained until
26Active LTS since 28 October 202630 April 2029
24Maintenance LTS30 April 2028
22Maintenance LTS30 April 2027
20 and olderEnd of lifeAlready ended

nvm install --lts picks the newest LTS release. If your project, host or a native add-on has not been tested with that line yet, install the major version they support instead.

Install nvm

You need curl (or wget) and a bash, zsh or other POSIX-compatible shell. The fish shell is not supported by nvm.

sudo apt update
sudo apt install curl

Piping a download straight into a shell runs code you have not read. To look first:

curl -o nvm-install.sh https://raw.githubusercontent.com/nvm-sh/nvm/v0.41.0/install.sh
less nvm-install.sh
bash nvm-install.sh

The installer puts nvm in ~/.nvm (or under $XDG_CONFIG_HOME if you set it) and adds lines that load it to a shell profile such as ~/.bashrc or ~/.zshrc. Close the terminal and open a new one, or run source ~/.bashrc. Then check:

command -v nvm

It should print nvm. Use command -v, because nvm is a shell function and which nvm will not find it.

Install and switch Node.js versions

nvm install --lts          # newest LTS release
nvm install 24             # newest release of the 24 line
nvm ls                     # installed versions
nvm ls-remote --lts        # LTS releases you can install
nvm use 24                 # switch the current shell
nvm alias default 24       # version for new shells

nvm use changes only the shell you run it in. Set the default alias to decide what a new terminal starts with.

Pin a project with .nvmrc

Put one version in a file called .nvmrc in the project’s root and commit it:

echo "24" > .nvmrc
nvm install     # installs the version named in .nvmrc if it is missing
nvm use         # switches to it

The file takes one version that nvm understands, such as 24, an exact release number, lts/* or node. It does not take npm-style ranges. With >=16.0.0 in the file, nvm 0.39.0 answered version ">=16.0.0 -> N/A" is not yet installed. If you want to declare a range, that belongs in the engines field of package.json.

nvm does not switch automatically when you enter a directory. Run nvm use, or add one of the shell integration snippets from the nvm README.

Global packages belong to one version

Packages installed with npm install -g are stored per Node.js version, so they seem to disappear after you switch. To carry them over while installing a new line:

nvm install --reinstall-packages-from=22 24

You do not need sudo for global installs under nvm. A prefix setting in ~/.npmrc is incompatible with nvm; remove it if nvm complains.

Cron jobs and services do not load nvm

nvm is loaded by your shell profile. A cron job, a systemd service or a script started by another program usually does not read that file, so node is “not found” there even though it works in your terminal. Look up the absolute path and use it:

nvm which 24

The path contains the full version number, so update the job or service after you upgrade. For a server where services matter more than switching versions, a system-wide installation may be simpler than nvm.

Troubleshooting

nvm: command not found

Open a new terminal first. If it still fails, check that the loading lines exist:

grep -n NVM_DIR ~/.bashrc ~/.profile ~/.zshrc 2>/dev/null

If they are missing, run the installer again, or add the loading lines shown in the nvm README to the profile your shell actually reads.

The wrong node runs

type -a node
nvm current

An older system installation may still be on the path. Check what depends on it before removing it: sudo apt remove nodejs lists what will be removed and asks before continuing. Avoid deleting files under /usr/local by hand unless you know which installation put them there.

Uninstall

Remove one Node.js version with nvm uninstall 22 (switch away from it first). To remove nvm itself:

nvm_dir="${NVM_DIR:-$HOME/.nvm}"
nvm unload
rm -rf "$nvm_dir"

Then delete the nvm lines from your shell profile. Check the value of nvm_dir with echo "$nvm_dir" before running rm -rf.

Related guides

Working on Windows? Start with installing WSL2 and run these steps inside your Ubuntu distribution. Keep the project files in the Linux file system; see moving files between Windows and WSL.

Share this post

Previous WSL2 Backup and Restore: Export Safely and Verify Recovery Next Dynex Large Transactions: Read Transfers, Turnover and Data Coverage

Leave a comment

Your email address will not be published. Required fields are marked *