How to easily switch between different versions of Nodejs on your system.

Introduction

Easily switch between different versions of Nodejs on your system.

In this blog article we’ll learn how to switch to a default version when using nvm

NVM is a tool that handles what versions of Nodejs you can use. Let’s say …


This content originally appeared on DEV Community and was authored by Nmurgor

Introduction

Easily switch between different versions of Nodejs on your system.

In this blog article we'll learn how to switch to a default version when using nvm

NVM is a tool that handles what versions of Nodejs you can use. Let’s say one’s working on a cutting edge library that requires the latest version, they would switch/install a version of Nodejs that is compatible with the library.

Scenario two, one is working on a project that requires an older version of Nodejs, let's say version 8.0.0. Installing and reinstalling Nodejs becomes hectic and cumbersome.

nvm makes handling versions of Nodejs rather painless.

NVM, (Node Version Manager) enables one to:

  1. Install different versions of Nodejs
  2. Switch to different versions of Nodejs
  3. Set a default Nodejs version from the installed versions
  4. Remove installed versions of Nodejs

Install nvm

This assumes that nvm installed already, if not, install nvm by:

# install script for nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

Note: Curl installation on your system is also required. Curl enables one to make http request from the commandline.

After downloading and running the bash script, set your profile file ~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc so that nvm is available system-wide.

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

Check if nvm installed correctly by running:

nvm -v
# prints nvm help menu for various options

terminal screenshot showing nvm

Install a different version of nodejs

To install a different node version using nvm:

nvm install 14.0.0

NVM handles the installation of the Nodejs version for you, afterwards , you may use this version when needed or as needed:

To use the Nodejs version from above:

nvm use 14.0.0

This command tells NVM to switch Nodejs to this version, the changes apply system-wide which is kinda cool, isn't it?

Set a default version of Nodejs using NVM

To set a default version of Nodejs using nvm, use this syntax:

nvm alias defaut <your_nodejs_default_version>

To switch to version we installed above 14.0.0, run:

nvm alias default 14.0.0
node -v # prints 14.0.0

NVM makes handling nodejs versions on your system rather painless and easy especially if you heavily use Nodejs as a tooling for your frontend work flow.

NVM offers more options such as:

  • uninstall a Nodejs version
  • Switch to a Nodejs version, nvm use <nodejs_version>

Further refference:
https://github.com/nvm-sh/nvm


This content originally appeared on DEV Community and was authored by Nmurgor


Print Share Comment Cite Upload Translate Updates
APA

Nmurgor | Sciencx (2021-12-16T09:01:18+00:00) How to easily switch between different versions of Nodejs on your system.. Retrieved from https://www.scien.cx/2021/12/16/how-to-easily-switch-between-different-versions-of-nodejs-on-your-system/

MLA
" » How to easily switch between different versions of Nodejs on your system.." Nmurgor | Sciencx - Thursday December 16, 2021, https://www.scien.cx/2021/12/16/how-to-easily-switch-between-different-versions-of-nodejs-on-your-system/
HARVARD
Nmurgor | Sciencx Thursday December 16, 2021 » How to easily switch between different versions of Nodejs on your system.., viewed ,<https://www.scien.cx/2021/12/16/how-to-easily-switch-between-different-versions-of-nodejs-on-your-system/>
VANCOUVER
Nmurgor | Sciencx - » How to easily switch between different versions of Nodejs on your system.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/16/how-to-easily-switch-between-different-versions-of-nodejs-on-your-system/
CHICAGO
" » How to easily switch between different versions of Nodejs on your system.." Nmurgor | Sciencx - Accessed . https://www.scien.cx/2021/12/16/how-to-easily-switch-between-different-versions-of-nodejs-on-your-system/
IEEE
" » How to easily switch between different versions of Nodejs on your system.." Nmurgor | Sciencx [Online]. Available: https://www.scien.cx/2021/12/16/how-to-easily-switch-between-different-versions-of-nodejs-on-your-system/. [Accessed: ]
rf:citation
» How to easily switch between different versions of Nodejs on your system. | Nmurgor | Sciencx | https://www.scien.cx/2021/12/16/how-to-easily-switch-between-different-versions-of-nodejs-on-your-system/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.