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.
curl must be installed on your server. Most Linux distributions include it by default.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.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
For Bash:
source ~/.bashrc
For Zsh:
source ~/.zshrc
nvm --version
A version number confirms NVM is installed and ready to use.
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.
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.
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
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.
source ~/.bashrc or source ~/.zshrc depending on your shell, then try again.cat ~/.bashrc | grep nvm. If nothing is returned, add the NVM initialisation block to your profile manually and reload.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.
nvm alias default <version> to set a persistent default, replacing <version> with your target version number..nvmrc file to the project root as described above.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.
Get scalable resources with our VPS hosting with root access and optional software.
Get VPS HostingPerfect for websites and small businesses unlimited bandwidth with cPanel hosting.
Get cPanel Hosting