Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

NVM: Manage Multiple Versions of Node.js on a Single System

Developers often have to depend on multiple versions of the same language, framework, or library. This can happen because one project might depend on the latest version of a language, whereas another project might require a previous release.Some operating systems and/or languages don’t make the task of using multiple versions of the same language easy. If you happen to use Linux as your development platform and Node.js as one of the many languages you work with, you’re in luck, as there’s a handy tool to make this fairly simple.The tool in question is called NVM, which stands for Node Version Manager. NVM can be installed on many different Linux distributions, such as Ubuntu, RHEL, CentOS Stream, Rocky Linux, AlmaLinux, and Debian, as well as MacOS and Windows (via Windows Subsystem for Linux).Essentially, NVM is a version manager for Node.js that is installed on a per-user basis and is invoked from the command line on any POSIX-compliant shell (such as sh, dash, ksh, zsh, and bash).I’m going to show you how to install and use NVM on Ubuntu Server 22.04.3 and Rocky Linux 9.To use NVM, you’ll need the following:That’s it. Let’s get to work.Log into your Ubuntu Server instance. If your server includes a desktop environment, open a terminal window.The next step is to install a few dependencies, which can be done with a single command:Next, download and run the installation script with the command:Once the command completes, log out and log back into your Ubuntu server instance.The installation of NVM on Rocky Linux is similar to that of Ubuntu, the only difference being the installation of the dependencies.To install the dependencies, log into your Rocky Linux instance and, if necessary, open a terminal window. Then, issue the following command to install the dependencies:The installation of the dependencies will take considerably longer on Rocky Linux than it does on Ubuntu. When it completes, you can then issue the same install command on Rocky Linux as you did Ubuntu, which is:When the command completes, log out of Rocky Linux and log back in. You can then verify the installation with the command:The output should be something like this:NVM is now installed and ready to use.If you find the prompt returns that NVM isn’t installed, you might have to reload your .bashrc script with the command:Now that NVM is installed, you can use it to install different versions of Node.js. This process is the same, regardless of which distribution you are using. With NVM, you’ll find it possible to install Node.js versions from v0.1.14 all the way to v20.7.0. Of course, you probably won’t want to go all the way back to beta releases and as Node.js is upgraded, newer releases will be added.To find the complete list of available Node.js releases for NVM, issue the command:The output will look something like this:Let’s say your current project requires Node.js version 19.0.1. To install this version, the command would be:When the command completes, you can verify the installation with the command:You should see the following output:->      v19.0.1         systemdefault -> v19.0.1If you’ve installed Node.js from your default package manager (such as apt-get), you might see a system entry in the output. If you want to use the version of Node.js installed by the system, you could issue the command:If you have multiple versions of Node.js installed, you can choose which one to use with a command like:The output for the above command will look like this:With NVM, you can install as many versions of Node.js as needed and switch back and forth between versions with ease. Any time a project demands a different release, switch with the nvm use command and you’re good to go.Community created roadmaps, articles, resources and journeys fordevelopers to help you choose your path and grow in your career.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

NVM: Manage Multiple Versions of Node.js on a Single System

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×