Thursday, September 14, 2023
HomeWeb DevelopmentMounting Several Variations of Node.js Making use of nvm-- SitePoint

Mounting Several Variations of Node.js Making use of nvm– SitePoint

When dealing with Node.js, you could run into circumstances where you require to mount numerous variations of the runtime.

For instance, perhaps you have the most up to date variation of Node established on your maker, yet the job you will begin working with calls for an older variation. Or perhaps you’re updating an old Node job to a much more contemporary variation and also it would certainly come in handy to be able to change in between both while you make the change.

Without an excellent device, this would certainly imply investing a great deal of effort and time by hand uninstalling and also re-installing Node variations and also their worldwide bundles. Luckily, there’s a much better means!

Presenting nvm

nvm represents Node Variation Supervisor. As the name recommends, it aids you handle and also change in between various Node variations effortlessly. It offers a command-line user interface where you can mount various variations with a solitary command, established a default, button in between them and also far more.

OS Assistance

nvm sustains both Linux and also macOS, yet that’s not to state that Windows individuals need to lose out. There’s a 2nd job called nvm-windows that supplies Windows individuals the alternative of conveniently handling Node settings. In spite of the name, nvm-windows is not a duplicate of nvm, neither is it associated with it. Nevertheless, the standard commands listed here (for setting up, listing and also changing in between variations) need to help both nvm and also nvm-windows.


Allowed’s initial cover setup for Windows, macOS and also Linux.


Initially, we require to do a little prep work:

  • uninstall any kind of existing variations of Node.js
  • erase any kind of existing Node.js setup directory sites (such as C: Program Filesnodejs)
  • erase the existing npm mount area (such as C: Customers<< customer>> AppDataRoamingnpm)

Hereafter, download and install and also run the most current steady installer and also you need to be great to go!


Unlike Windows, eliminating previous Node and also npm setups in macOS and also Linux is optional. If this is something you wish to do, there are a lot of great sources readily available online. For instance, right here’s just how to get rid of Node on macOS and also on Linux As well as right here’s just how you can get rid of any kind of previous npm setup you could have.

You can mount nvm making use of swirl or Wget.

For swirl, run the complying with on your terminal:

 crinkle -o- |  celebration

Or with Wget:

 wget -qO- |  celebration

Keep in mind that the variation number ( v0.35.2) will certainly transform as the job creates, so it deserves inspecting the appropriate area of job’s web page to discover one of the most current variation.

This will certainly duplicate the nvm database to ~/. nvm and also will certainly make the called for adjustments to your celebration account, to ensure that nvm is readily available from throughout your terminal.

Which’s it! Reload (or reactivate) your incurable and also nvm prepares to be utilized.

Making use of nvm

If mounted properly, the nvm command is readily available throughout you incurable. Allow’s see just how to utilize it to handle Node.js variations.

Install Several Variations of Node.js

Among one of the most fundamental parts of nvm is, certainly, setting up various variations of Node.js. For this, nvm offers the nvm mount command. You can mount certain variations by running this command adhered to by the variation you desire. For instance:

 nvm  mount  12.141.

By running the above in an incurable, nvm will certainly mount Node.js variation 12.14.1

Pointer: nvm-windows individuals will certainly need to run nvm usage 12.14.1 after setting up.

nvm adheres to SemVer, so if you wish to mount, for instance, the most up to date 12.14 spot, you can do it by running nvm mount 12.14

nvm will certainly after that mount Node.js variation 12.14. X, where X is the greatest readily available variation. At the time of creating, this is 1, so you’ll have the 12.14.1 variation mounted on your system.

You can see the complete checklist of readily available variations by running nvm ls-remote

For nvm-windows, this is nvm ls readily available

Pointer: detailing all readily available Node variations generates a great deal of result. Linux individuals could such as to qpipe that to much less or grep the variation they desire. For instance, nvm ls-remote|much less, or nvm ls-remote|grep v12


When setting up a Node.js circumstances, nvm will certainly likewise mount a suitable npm variation. Each Node variation could bring a various npm variation, and also you can run npm -v to examine which one you’re presently making use of. Around the world mounted npm bundles aren’t shared amongst various Node.js variations, as this might create conflicts. Instead, they’re mounted along with the present Node variation in ~/. nvm/versions/node/<< variation>>/ lib/node _ components This has actually the included benefit that individuals will not need sudo benefits to mount worldwide bundles.

Luckily, when setting up a brand-new Node.js variation, you can re-install the npm worldwide bundles from a particular variation. For instance:

 nvm  mount v12.14.1-- reinstall-packages-from = 10.181.

By running the above, nvm will certainly mount Node.js variation 12.14.1, the equivalent npm variation, and also re-install the worldwide npm bundles you had actually mounted for the 10.18.1 variation.

If you’re unsure what the most up to date variation is, you can utilize the node alias:

 nvm  mount node.

This will presently draw in variation 13.6.0

Or you can mount one of the most current LTS launch, making use of:

 nvm  mount-- lts.

This will presently draw in variation 12.14.1

You can likewise uninstall any kind of circumstances you no more believe serves, by running:

 nvm uninstall  13.60.

Changing In Between Variations

Up until now, we have actually seen just how to mount various Node variations. Currently allow’s experience just how to change in between them. Allow me initial note that when a brand-new variation is mounted, it’s instantly used. So if you mount the most up to date Node.js variation, and also run node -v right after, you’ll see the most up to date variation result.

To change with mounted variations, nvm offers the nvm usage command. This functions likewise to the mount command. So, you require to follow this by a variation number or a pen name.

Change to Node.js variation 13.6.0:

 nvm usage  13.60.

Change to Node.js variation 12.14.1:

 nvm usage  12.141.

Change to the most up to date Node.js variation:

 nvm usage node.

Change to the most up to date LTS variation:

 nvm usage-- lts.

When switching over to a various variation, nvm will certainly make the node circumstances in your incurable symlink to the correct Node.js circumstances.

Customized Pen Names

You can likewise produce customized pen names past the ones that feature nvm. For instance, by running:

 nvm  pen names awesome-version  13.60.

You’re establishing a pen name with the name “awesome-version” for Node.js variation 13.6.0 So, if you currently run:

 nvm usage awesome-version.

nvm will certainly change node to variation 13.6.0 You can erase a pen name by running:

 nvm  unalias awesome-version.

You can likewise establish a default circumstances to be utilized in any kind of covering, by targeting a variation to the “default” pen names, thus:

 nvm  pen names default  12.141.

Detailing Mounted Circumstances

Any time you can examine which variations you have actually mounted by running:

 nvm  ls

This will certainly show something looking like the photo listed below.

nvm versions list

The entrance in eco-friendly, with an arrowhead left wing, is the present variation in operation. Listed below the mounted variations, there’s a checklist of readily available pen names. Attempt performing the complying with currently:

 nvm usage node.
nvm  ls

It will certainly show thus:

nvm use and versions list

You can likewise examine what is the present variation in operation with the command:

 nvm current.

Define a Node Variation on a Per-project Basis

Variation supervisors such as rbenv enable you to define a Ruby variation on a per-project basis (by creating that variation to a ruby-version documents in your present directory site). This is type of feasible with nvm because, if you produce a nvmrc documents inside a task and also define a variation number, you can cd right into the job directory site and also kind nvm usage nvm will certainly after that check out the components of the nvmrc documents and also usage whatever variation of Node you define.

If it is very important to you that this occurs instantly, there are a number of bits on the job’s web page for you to contribute to your bashrc or zshrc submits to make this occur.

Below’s the ZSH fragment. Location this listed below your nvm config:

 autoload -U add-zsh-hook.
tons- nvmrc()  {
   regional  node_version ="$( nvm variation)"
   regional  nvmrc_path ="$( nvm_find_nvmrc)"

   if [ -n "$nvmrc_path" ];  after that
     regional  nvmrc_node_version =$( nvm variation "$( feline "$ {nvmrc_path} ")")

     if [ "$nvmrc_node_version" = "N/A" ];  after that
nvm  mount
     elif [ "$nvmrc_node_version" != "$node_version" ];  after that
nvm usage.
   elif [ "$node_version" != "$(nvm version default)" ];  after that
     resemble " Going back to nvm default variation"
nvm usage default.
add-zsh-hook chpwd load-nvmrc.

Currently, when you become a directory site with a nvmrc documents, your covering will instantly transform Node variation.

Automatically apply nvm use

Various other nvm Commands

nvm offers a number of various other commands that are advanced or much less frequently utilized.

You can run a command straight for a set up variation without switching over the node variable:

 nvm run  13.60-- variation.

You can run a command on a sub-shell, targeting a particular variation:

 nvm  director  13.60 node-- variation.

You can obtain the course to the Node.js executable of a particular mounted variation:

 nvm  which  13.60.

This may be valuable when setting up a full-screen editor plugin that requires to recognize where your present variation of Node lives.


nvm is a terrific device for any kind of Node.js programmer. It allows a concern-free setup and also simple changing in between various variations, conserving time wherefore truly matters.

A thanks keep in mind to Tim Caswell, the developer of nvm, as well as likewise to Corey Butler for the nvm for Windows assistance, and also certainly to those adding to these fantastic jobs. Your job is significantly valued by the Node.js area.

What regarding you? Do you utilize nvm? Just how has your experience been with it? Beg Michael or James on Twitter if you wish to conversation.

Frequently Asked Questions regarding Node Variation Supervisor (NVM)

What is NVM?

Node Variation Supervisor (NVM) is a command-line device that permits you to conveniently handle numerous setups of Node.js and also button in between various variations on the very same maker.

Why would certainly I require NVM?

NVM serves when you deal with jobs that need certain variations of Node.js. It permits you to change in between these variations perfectly, making sure compatibility and also preventing variation disputes.

Just how do I mount NVM?

You can mount NVM by complying with the setup directions attended to your os. Commonly, it entails running a manuscript in your incurable or command trigger.

Which os are sustained by NVM?

NVM sustains Linux, macOS, and also Windows running systems.

Just how do I mount a particular variation of Node.js making use of NVM?

You can mount a particular variation of Node.js making use of the command nvm mount[version] For instance, nvm mount 14.17.3 will certainly mount Node.js variation 14.17.3.

Just how do I change in between Node.js variations making use of NVM?

To change in between Node.js variations, you can utilize the command nvm usage[version] As an example, nvm usage 12.22.6 will certainly change to Node.js variation 12.22.6.

Can I establish a default Node.js variation to be utilized?

Yes, you can establish a default Node.js variation making use of the command nvm alias default[version] This variation will certainly be utilized whenever you open up a brand-new incurable home window.

Just how do I detail the Node.js variations I have mounted with NVM?

You can detail the mounted Node.js variations making use of the command nvm ls code> > or nvm checklist code>>.

Can I uninstall a particular Node.js variation with NVM?

Yes, you can uninstall a particular Node.js variation making use of the command nvm uninstall [version] code>>. For instance, nvm uninstall 10.15.0 will certainly uninstall Node.js variation 10.15.0.

Does NVM just handle Node.js variations?

No, NVM can likewise handle setups of npm (Node Plan Supervisor) along with Node.js variations. When you change Node.js variations, NVM will certainly likewise change to the equivalent npm variation.

Is NVM restricted to steady launches of Node.js?

No, NVM permits you to mount and also handle steady, LTS (Long-Term Assistance), and also also advancement variations of Node.js.

Can I utilize NVM with various other Node.js variation supervisors?

It’s typically suggested to utilize just one Node.js variation supervisor each time to stop disputes. Making use of NVM along with various other supervisors might bring about unforeseen actions.

Just how do I upgrade NVM itself?

You can upgrade NVM making use of the command nvm upgrade.

Is NVM restricted to Node.js, or can it handle various other runtime variations as well?

While NVM’s main emphasis gets on Node.js, there are community-maintained jobs like “pyenv” for Python variation administration that are influenced by NVM’s idea.

Can NVM collaborate with various coverings?

Yes, NVM can be set up to collaborate with numerous coverings like Celebration, Zsh, and also Fish. The setup directions commonly consist of information on setting up NVM for your recommended covering.


Most Popular

Recent Comments