In this tutorial, you will learn about NVM and how you can use it to install and more easily manage NodeJS . NVM stands for node version manager. You can use NVM to install multiple different versions of Node all on the same machine! If you will only ever need to work on a single project that will never ever change then installing NodeJS normally will suffice. When you work in a large company and you have multiple projects to work on, things become trickier.
Like all good programming languages, node release updates every once in a while. With each new update of node comes new features, syntax improvements etc... The issue with all these updates is compatibility. If you write a script in Node 10 using some new feature, then it might not run in Node v8. If you have two projects, one that only works on Node v10 and one that works on Node 8, what do you do? Constantly, uninstalling and re-installing NodeJS is a pain...this is where NVM comes into play. NVM is an essential tool that will make your life easy. By using NVM you can switch between different node versions using a single command!
How To Install NVM
After installing homebrew, close and open your terminal, then type this command:
Next, type in:
You will likely need to create and configure a bash profile and create an alias for NVM to work optimally. You can do this within the terminal, by typing:
In here, if you do not see anything related to NVM then add in this snippet:
Save the file
(CTRL + O) then
(CTRL + X). Close and re-open the terminal. Now type this command:
If everything has gone according to plan the terminal should load without any warnings and NVM should be installed successfully!
How To Install NPM with NVM
Now you have NVM installed, we can install a version of NodeJS. To install Node you can type:
You can set NVM to use NodeJS using this command:
To install the latest version of NodeJS using the
To install a specific version of NodeJS using this command:
With NVM and node installed you can switch between NodeJS versions using this command:
You should now be able to manage multiple versions of NodeJS via the terminal. Happy Coding 🤘