How to Switch Node Version on Ubuntu

Feb 13, 2024

2 mins read

Published in
---

Managing Node.js Versions on Ubuntu with NVM**

Ubuntu users often work on various Node.js projects, each requiring a specific version. This guide will walk you through the process of managing Node.js versions effortlessly on Ubuntu using Node Version Manager (NVM).

Prerequisites: Before proceeding, make sure you have NVM installed. If not, you can install it by running:

1
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Restart your terminal or run source ~/.bashrc (or ~/.zshrc if you’re using Zsh) after installation.

Step 1: List Available Node.js Versions:

Use the following command to list the available Node.js versions:

1
nvm ls-remote

Select the version you want to switch to.

Step 2: Install Node.js Version:

Install the desired Node.js version using the following command:

1
nvm install <version>

Replace <version> with the version you’ve chosen.

Step 3: Switch Node.js Version:

To switch between installed Node.js versions, use:

1
nvm use <version>

This command sets the specified version as the active one.

Step 4: Set Default Node.js Version:

If you wish to set a specific version as the default for new shells, use:

1
nvm alias default <version>

Replace <version> with your preferred default version.

Step 5: Check Current Node.js Version:

Verify that the switch was successful by checking the current Node.js version:

1
node -v

This should display the version you set.

Step 6: Use NVM to Manage Node.js Versions:

NVM simplifies the management of Node.js versions. You can list installed versions with:

1
nvm ls

And remove an installed version with:

1
nvm uninstall <version>

Effectively managing Node.js versions on Ubuntu is crucial for project compatibility. Node Version Manager (NVM) streamlines this process, enabling you to effortlessly switch between Node.js versions.

Sharing is caring!