Coner Murphy

Published on 12 Apr 2021 | 4 Minute Read

How to Install Multiple NodeJS Versions Using NVM

Upgrading and managing multiple NodeJS versions can be a pain for many developers, here's how to do it easily with NVM.

How to Install Multiple NodeJS Versions Using NVM

Recently, while I was updating my website I also wanted to upgrade the NodeJS version. Having explored this path in the past I knew it could be painful.

So on I went down the journey of upgrading NodeJS. I found there is multiple ways of tackling this problem. But, the best method I found is NVM or Node Version Manager.

In this post, we'll look at using NVM to install multiple NodeJS versions and how to switch between them at the drop of a hat.

Installing NVM

To install NVM it's as simple as running the authors install script which you can find here. You can either paste this into your terminal or you can run one of the below `curl` or `wget` commands to do it for you:

1curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
2
3wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

After running this script, you should notice the NVM repository has been copied into a `~/.nvm` folder. Following this, the below code should now be added to your current terminal profile.

For example, I use ZSH for my terminal which is located in `~/.zshrc`. After installing NVM I should find the below code copied into that file.

1export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
2[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
bash

If everything went smoothly, NVM should now be installed!

Using NVM

Using NVM is simple, let's take a look at some of the most common commands you'll use:

Installing a New NodeJS Version

To install a new NodeJS version, you can use one of the below commands.

To get the latest version you can run:

1nvm install node # "node" is an alias for the latest version
bash

Or, if you have a particular version in mind:

1nvm install 14.8.0 # or 10.10.0, 8.9.1, etc
bash

NOTE: The first version you install becomes the default that new shell windows use.

Checking Installed NodeJS Versions

If you want to check what versions of Node you have installed you can run:

1nvm ls
bash

Checking What NodeJS Versions Can Be installed.

If you're interested in seeing what versions you can install using NVM, you can run:

1nvm ls-remote
bash

Switching NodeJS Versions

To switch between versions you can use:

1nvm use 14.8.0 # or 10.10.0, 8.9.1, etc
bash

Uninstalling Old NodeJS Versions

If you want to uninstall a version of Node you no longer need:

1nvm uninstall 14.8.0 # or 10.10.0, 8.9.1, etc
bash

Troubleshooting

If you were like me and run into the error `nvm: command not found` every time you try to run one of these commands. Or, you have another issue you can check out the troubleshooting section on the NVM GitHub Repo.

Unfortunately, my issue wasn't on the troubleshooting section so I had to do some digging. Here's how I solved it.

After retracing my steps, I found that the original install script hadn't added the below code to my `~/.zshrc`.

1export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
2[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
bash

After I opened my `~/.zshrc` file and dropped in that code at the bottom, NVM started to work. If you're getting the `nvm: command not found` error try the troubleshooting guide first. If that doesn't help, check it was installed correctly.

If neither of these work I would recommend opening an issue on GitHub for some support.

Conclusion

That's it! NVM should now be installed and you should be able to install and use as many NodeJS versions as you please.

I hope you found this post helpful. If you did I would greatly appreciate you sharing it with others so they can find it helpful too. If you would like to see more content like this, please consider following me on Twitter.

Until next time, thank you for reading. šŸ˜ƒ



šŸ‘„

Latest Content...

What Iā€™m up to and more.

  • How to make a flicker-free dark theme toggle with Next.js, TailwindCSS, and `next-themes`

    7 Jun 2022

    How to make a flicker-free dark theme toggle with Next.js, TailwindCSS, and `next-themes`

    Here's how to build a dark/light theme toggle in Next.js using TailwindCSS and the next-themes npm package to make it load and transition flicker-free.

  • 3 Reasons Why You Need to Design Components and Not Pages

    26 Jun 2021

    3 Reasons Why You Need to Design Components and Not Pages

    If you want to design better websites then you need to stop designing at a page level and start thinkning about components. Here's 3 reasons why.

  • 6 Twitter Analytics Terms You Need to Know to Grow an Audience in 2021

    26 Jun 2021

    6 Twitter Analytics Terms You Need to Know to Grow an Audience in 2021

    Building a Twitter audience is a great way to grow your business. So, here are 6 Twitter analytics terms you need to know and how to measure them.

Want to read more?

View all posts here