How to manage Node.js versions with NVM

By Angus Published 9 March 2026 5 min read

Running multiple Node.js projects on a single VPS often means each project needs a different Node.js version. Installing Node.js globally with a package manager gives you one version for everything, which causes compatibility errors when versions conflict. Node Version Manager (NVM) solves this by letting you install and switch between multiple Node.js versions from the command line.

This guide covers installing NVM on your VPS, installing Node.js versions, switching between them and automating version selection per project.

Before you begin

  • You need SSH access to your VPS. See our guide on connecting to your server via SSH.
  • curl must be installed on your server. Most Linux distributions include it by default.
  • We recommend removing any globally installed Node.js version before installing NVM to avoid conflicts.

Install NVM on your VPS

The official NVM installation script downloads the tool and adds the required configuration to your shell profile automatically. Running it with curl fetches and executes the script in a single command.

  1. Connect to your VPS via SSH.
    Open your terminal and log in to your server.
  2. Run the NVM install script.
    The following command downloads and runs the official NVM v0.40.3 installation script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
  1. Reload your shell configuration.
    The install script adds NVM to your shell profile, but you need to reload it for the changes to take effect in your current session. Run the command that matches your shell:

For Bash:

source ~/.bashrc

For Zsh:

source ~/.zshrc
  1. Confirm the installation.
    Check that NVM is available by printing its version:
nvm --version

A version number confirms NVM is installed and ready to use.

Install and switch Node.js versions

With NVM installed, you can install any Node.js version and switch between them at any time. NVM keeps each version isolated so changing version for one project does not affect another.

To install the latest stable release of Node.js, run:

nvm install node

To install a specific version, replace node with the version number you need, for example:

nvm install 20

To see all versions currently installed on your server, run:

nvm ls

To see all versions available to install from the remote repository, run:

nvm ls-remote

To switch to an installed version in your current shell session, run:

nvm use 20

This change applies only to the current terminal session. Opening a new session reverts to the default version.

Set a default Node.js version

The default version is the one NVM activates automatically in every new shell session. Setting this prevents you from having to run nvm use every time you open a terminal.

To set a specific version as the default, run one of the following. You can target the latest installed version, a major version or a precise minor version:

nvm alias default node
nvm alias default 20
nvm alias default 20.11

New shell sessions now activate the version you specified.

Pin a Node.js version to a project with .nvmrc

A .nvmrc file tells NVM which Node.js version a project requires. Placing one in your project’s root directory means anyone working on the project can activate the correct version by running nvm use or nvm install without specifying a version number.

Navigate to your project directory and create the file with the version you need. For example, to pin to Node.js 20:

echo "20" > .nvmrc

You can also use the lts/* alias to always target the latest LTS release, or node for the latest stable version:

echo "lts/*" > .nvmrc

Once the file exists, run either of the following from within the project directory. NVM reads the file and activates or installs the specified version:

nvm use
nvm install

Troubleshooting

nvm: command not found after installation

The install script adds NVM to your shell profile, but the current session does not pick up the change until you reload it. This is the most common cause of a missing nvm command immediately after installation.

  • Run source ~/.bashrc or source ~/.zshrc depending on your shell, then try again.
  • If the problem persists, close your SSH session completely and reconnect. This forces a full profile reload.
  • Confirm the install script added the NVM lines to your profile by running cat ~/.bashrc | grep nvm. If nothing is returned, add the NVM initialisation block to your profile manually and reload.

Node.js version does not persist between sessions

nvm use changes the active version for the current shell session only. If you open a new session and find the wrong version is active, you have not set a default.

  • Run nvm alias default <version> to set a persistent default, replacing <version> with your target version number.
  • For project-specific versions, add a .nvmrc file to the project root as described above.

Wrapping up

You installed NVM on your VPS, installed Node.js versions, switched between them and pinned versions to individual projects using .nvmrc. Your server can now run multiple Node.js projects side by side without version conflicts.

To go further, review how to secure your VPS and see our guide on installing a MERN stack for a practical example of Node.js in a full server environment. You may also find our guide on installing Yarn on Linux useful for managing Node.js package dependencies.

Our Node.js hosting plans are built for running Node.js applications in production.

Need more power?

Get scalable resources with our VPS hosting with root access and optional software.

Get VPS Hosting

Starting something new?

Perfect for websites and small businesses unlimited bandwidth with cPanel hosting.

Get cPanel Hosting