Node.js projects often depend on different runtime majors because frameworks, build tools, and deployment targets move on separate schedules. nvm keeps those versions under one user account so a developer can test or run a project without replacing the system Node.js package.
nvm is loaded as a shell function, so it changes the current shell's PATH when a version is selected. The install script adds loader lines to the user's shell profile, and the same loader can be sourced manually when the current terminal session needs nvm immediately.
Development shells on Linux, macOS, or Windows WSL can keep project-specific versions isolated without affecting system services. The default alias controls new shells, while a project .nvmrc file lets nvm use select the runtime expected by that project directory.
Related: Install the latest Node.js on Ubuntu
Related: Create a Node.js project with npm
Steps to manage Node.js versions with nvm:
- Open a POSIX-compatible shell with curl and git available.
- Install nvm from the official release script.
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash => Downloading nvm from git to '/home/developer/.nvm' => Cloning into '/home/developer/.nvm'... ##### snipped ##### => Appending nvm source string to /home/developer/.bashrc => Appending bash_completion source string to /home/developer/.bashrc => Close and reopen your terminal to start using nvm or run the following to use it now:
Read remote install scripts before running them on managed workstations. The nvm installer clones into the current user's home directory and edits that user's shell profile.
- Load nvm into the current shell.
$ . "$HOME/.nvm/nvm.sh"
Closing and reopening the terminal loads the profile changes instead.
- Confirm the nvm command is loaded.
$ nvm --version 0.40.5
- Install the latest LTS Node.js line.
$ nvm install --lts Installing latest LTS version. Downloading and installing node v24.18.0... ##### snipped ##### Checksums matched! Now using node v24.18.0 (npm v11.16.0) Creating default alias: default -> lts/* (-> v24.18.0 *)
The exact patch version follows the current Node.js LTS release.
- Confirm the active Node.js runtime.
$ node --version v24.18.0
- Set the LTS line as the default for new shells.
$ nvm alias default lts/* default -> lts/* (-> v24.18.0 *)
- Install the project-required Node.js major line.
$ nvm install 22 Downloading and installing node v22.23.1... ##### snipped ##### Checksums matched! Now using node v22.23.1 (npm v10.9.8)
Replace 22 with the major, minor, or full version required by the project.
- Switch the current shell back to the LTS line.
$ nvm use --lts Now using node v24.18.0 (npm v11.16.0)
- Save the project runtime in .nvmrc.
- .nvmrc
22
- Switch to the version requested by .nvmrc.
$ nvm use Found '/srv/app/.nvmrc' with version <22> Now using node v22.23.1 (npm v10.9.8)
Run nvm use from the project root so nvm can find the nearest .nvmrc file.
- Confirm the active runtime changed to the project version.
$ node --version v22.23.1
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.