Managing multiple Node.js versions
Posted By : Karun Agarwal | 30-Sep-2021
As a developer, I often find myself working on different Node.js projects and at times they use different Node.js versions.
And, here comes the problem, how to manage different versions of node.js in your development environment?
Seeking some solutions through google, I met "nvm" i.e., "Node Version Manager". I will take you through steps to set up a node.js development environment using nvm and switching between versions.
1) Installing nvm
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
For changes to reflect, please close the terminal and open it again.
Now suppose, you are working on two projects, one of which uses Node.js v12 and another uses Node.js v14.
2) Install node.js v12 and node.js v14
nvm install 12
nvm install 14
Suppose you also want to set v12 as the default version,
3) Set v12 as the default version
nvm alias default 12
Please close the terminal and reopen it for changes to reflect.
And you are done.
Now, every time you open the terminal, the default node.js version of the environment will be v12. Suppose you are looking to use v14 though,
4) Switch to node.js v14
nvm use 14
After running this, the node.js version for that terminal session will become 14. Once you close the terminal and re-open, the environment will again be using v12 and you can re-run the above command to switch to v14 again.
Suppose you no more use node.js v12 and want to remove it.
5) Remove node.js v12
nvm uninstall 12
Thanks for reading the blog, hope you found the information useful.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Karun Agarwal
Karun is an avid and quick learner. He is a startup enthusiast who is quite passionate about technology and finance and loves working on the intersection of both. His hobbies include cooking, listening music, reading books, etc.