DEV Community

Shawon Saha
Shawon Saha

Posted on

Effortlessly Install or Switch Node Versions with NVM on Linux

Installing Node on a new Linux machine can be a frustrating experience, especially when you need a specific version or need to switch between different versions for different projects. The process of switching between versions can be a hassle and a nightmare. But there's good news! NVM (Node Version Manager) is a lifesaver for this problem. NVM makes it easy to install and switch between different versions of Node.js with just a few simple commands. Say goodbye to frustration and hello to easy Node version management with NVM on Linux.

Run Any one of these command

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

These commands will clone the nvm repository to a ~/.nvm directory on your device, and attempts to add the source lines from the snippet below to the correct profile file ~/.bash_profile or ~/.zshrc ~/.profile or ~/.bashrc

If it's failed to register then you need to manually input this snippet at the end the /.bashrc or /.zshrc if you use zsh

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

Now restart the terminal or run source ~/.bashrc

To verify if nvm is succesfully installed or not run nvm -v

In conclusion, NVM (Node Version Manager) makes managing Node.js versions on your Windows, Linux, or Mac device a breeze. With NVM, you can easily install, uninstall, and switch between different Node versions. To install the latest version of Node, simply run

nvm install latest
Enter fullscreen mode Exit fullscreen mode

To install a specific version such as X.Y.Z, use the command

nvm install 16.18.1 
Enter fullscreen mode Exit fullscreen mode

You can also set a specific version as the default by running

nvm alias default vX.Y.Z
Enter fullscreen mode Exit fullscreen mode

When you need to use a specific version on a project, simply run

nvm use vA.B.C
Enter fullscreen mode Exit fullscreen mode

NVM is a valuable tool for managing multiple Node.js versions across different projects that require different versions.

Learn More about commands here https://github.com/nvm-sh/nvm#usage

Top comments (3)

Collapse
 
adelak profile image
Adel-ak

In my 4 years of node development, nvm is the worst of the worst.

Try out volta volta.sh/, you'll never look back after that

Collapse
 
rennycat profile image
Jaruwat Thongchana

pnpm is node package manager and also version manager.

dev.to/rennycat/pnpm-can-manage-no...

Collapse
 
toyo_tomi profile image
Sacquer

n is also a neat version manager for Node.