I recently got into a problem where a project I was working on was not able to use anything other than node 8, which prevented me from experimenting with any new packages. So I gave nvm-windows a try and I could not be happier. Here’s what you need to do to make it work.

First, execute npm -g list --depth=0 and write down all those global packages you want to keep. Then do the same with yarn global list.

After everything is set up with nvm, you will need to install these global packages for every version of Node you decide to use. For me, I went with 14.4.0, 12.18.1 and 8.17.0 and so I had to repeat installing these 3 times. Of course, only if you really need them in each setup, otherwise just install what you need. For me, I use yarn 1.3.2 with node 8 and yarn 1.22.4 with node 12 and 14. Again, do what you need in each setup.

Go ahead and uninstall all global packages from both npm and yarn listings you just ran. Naturally, you want to clean up yarn global packages first, since yarn is one of npm global packages 😉

Now, go ahead and uninstall node, completely. I recommend geek-uninstaller for this.

Download and install the latest nvm-windows: https://github.com/coreybutler/nvm-windows/releases

Once nvm is installed, simply execute nvm install and the specified version of nodejs will be installed. You can pick a version from the nodejs release listing: https://nodejs.org/en/download/releases/

When you have more than one version of node installed, you can always check what you have by executing nvm list:

To switch to another version, simply execute nvm use .

At this point, go thoroughly through each version you installed and add all global packages you need. Keep in mind to specify the version of the package, if that is needed. For example, I used npm -g i yarn for my node versions 12 and 14, and npm -g i [email protected] for my node version 8.

In the future, if you want to update a given version, you can use nvm install NEW_VERSION --reinstall-packages-from=OLD_VERSION, as described in this stackoverflow answer.

And that’s that 🙂

Finally, if you ever forget the nvm commands, simply execute nvm:

Categories: Programming

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.