Create amazing web applications!

How to install NVM - Node Version Manager on Linux

In this tutorial, I will show you how to install different nodejs versions while not messing up your current server or development setup. Let's Code Pare.

by Anthony Pillos 2 minutes

linuxnvmcentosnodeglibcglibcxxnode version manager

How to install NVM - Node Version Manager on Linux

Introduction

Node.js is one of the most popular open-source platforms that you can easily use to build your backend or rest API that can easily scale because it can handle simultaneous connections which supports a non-blocking, event-driven server, due to its single-threaded nature.

As the team continues doing some upgrades, some of our programs are still stuck in the old version of node.js which sometimes we encounter some issues when we are trying to update from the latest version.

In this tutorial, I will show you how to install different nodejs version while not messing up you're current server or development setup.

STEP 1

To install or update your NVM, you should run the install script. To do that, use the following cURL or Wget command:

As of the time of writing, we are using NVM v0.38.0

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

or

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

STEP 2

After running the above commands, it's time to add a variable to your bash command. Normally, it was located from these file paths:

  • ~/.bash_profile
  • ~/.zshrc
  • ~/.profile
  • ~/.bashrc

Using nano or vim, open one of the files above. For example i will be using ~/.bash_profile

nano ~/.bash_profile

Then paste the code below, then hit crtl + o + enter then ctrl + x to close the file.

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

Then source ~/.bash_profile to set up environment for NVM:

source ~/.bash_profile

STEP 3

To check the available lists of available node version that you can use. Type this command.

nvm ls-remote

You will see a long lists of available version up-to the latest. Something like this below:

...
v14.14.0
v14.16.0   (LTS: Fermium)
v14.16.1   (LTS: Fermium)
v14.17.0   (Latest LTS: Fermium)
v15.0.0
v15.0.1
v16.0.0
v16.1.0
v16.2.0

NVM can install any of these versions available in the list. For example, to install version v16.2.0, type:

nvm install v16.2.0

To install the latest stable version, type:

nvm install stable

To switch to any version installed by nvm.

nvm use v15.0.1

NOTE

In case you've encounter errors such as glibc or glibcxx error not found, I got a solution for you pare. Please check our tutorial here: NVM installed, Getting GLIBC and GLIBCXX Error on Linux

TADAA

Voila!!!

I hope you enjoy our tutorial, Let me know incase you encounter any error I would love to answer that. Don't forget to subscribe to my Youtube Channel at Let's Code Pare - Youtube Channel

Buy Me A Coffee

Share Now

Want to get more 🔥 tips like this one?

Subscribe to get notified for our new dev tutorials

Let's Code Pare
Let's Code Pare Youtube Channel