DEV Community

Cover image for What is NVM?
jrob112
jrob112

Posted on

What is NVM?

Intoduction

With the use of Node.js, or node, we have the ability to have Javascript communicate with in a unified language in client/server side development.(1) The advantages that come with Node.js is the use of the Node Version Manager.

Advantages of NVM

With nvm, you are allowed to change versions quick and easy. Nvm stores multiple versions that have associated modules inside your user directory.(2) You can, with the use of commands, see a list of the versions that have been installed, change the default, change to a specific version, and others.

How to install NVM in Ubuntu

First, you need to run the installer in your ternimal.

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

# or

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Enter fullscreen mode Exit fullscreen mode

Depending on the commands available you can use either curl or bash. The directory for nvm will be installed. . If the configuration is not added automatically with the installation, you may add it yourself with the following command.(3)

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"
Enter fullscreen mode Exit fullscreen mode

Next, run the command

source ~/.zshrc || source ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

This will reload the configuration for your terminal for use.

After Installation

You will need to have the most updated versions available for you to use. Run this command.

nvm install latest
Enter fullscreen mode Exit fullscreen mode

The latest version of nvm will be installed. To check which versions you have installed run this command.

nvm ls
Enter fullscreen mode Exit fullscreen mode

A list of all the versions that have been installed with a description of which is set to default will show up. Here is an example.

       v16.20.2
       v18.18.1
->       system
default -> v18.19.0 (-> N/A)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v18.18.1) (default)
stable -> 18.18 (-> v18.18.1) (default)
lts/* -> lts/iron (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.2
lts/hydrogen -> v18.19.0 (-> N/A)
lts/iron -> v20.11.0 (-> N/A)
Enter fullscreen mode Exit fullscreen mode

If you need to set the default to another version, run the command.

nvm alais default [version]
Enter fullscreen mode Exit fullscreen mode

You may need to leave the default where it is, but want to use a specific version. You can run this command.

nvm use [version]
Enter fullscreen mode Exit fullscreen mode

If there is a version that you need and you do not have it installed you can run this commad to get a specific version.

nvm install [version]
Enter fullscreen mode Exit fullscreen mode

Conclusion

We have taken a look into a few of the advantages of NVM. Also, there has been a step-by-step installation process for users of Ubuntu(Linux) based services. Last, we looked into how to check which version have been installed, change your default setting,
and choose a specific version to use.

Reference Links
(1)https://www.baeldung.com/linux/update-nodejs-npm
(2)https://www.linode.com/docs/guides/how-to-install-use-node-version-manager-nvm/
(3)https://www.freecodecamp.org/news/node-version-manager-nvm-install-guide/

Top comments (0)