How to Reliably Install Node.js Using NVM on MacOS
Tags: node, nvm, macos
Published: 2020-01-27 22:06:19

Because JavaScript is an ever-growing programming language in terms of popularity and usability, so are the different ways of using its toolings such as <i>Node.js</i>. Let’s say you’re working on a new ReactJS app. You are most likely to end up using Node.js for the backend. More specifically, its core functionalities such as NPM. What if I told you there’s a <i>reliable</i> way of getting up and running with Node.js and, consequently, NPM? 

Allow me to introduce you to <b>NVM</b>, or short for <b>N</b>ode <b>V</b>ersion <b>M</b>anager. This tool allows us to have a more intuitive process when it comes to installing, maintaining and switching between the different versions of Node.js that are either stable releases or not. While it's still common practice to utilize tools such as <i>Homebrew</i> to install Node.js in your machine, I hope, with this article, to convince you not to. 

In the introductory lines of this article, I mentioned using tools such as NPM (which comes bundled with Node.js) being common practice among professionals nowadays. What is not so often talked about, is how prone to errors you become when you use a package manager such as Homebrew to install Node.js and consequently another package manager which is,  in this case, NPM. 

<h3> Why not Homebrew </h3>
Personally, I have run into a multitude of bugs and errors when working with ReactJS and trying to install a given version of Node.js along with my project’s dependencies. Another reason why I decided to stop using Homebrew for my Node.js needs, is that while learning some <i>React Native</i>, the instructor I had been working with was using a different version of Node.js that I was. Naturally, I tried installing said version via Homebrew which led me to some good 30 minutes of tinkering around in an attempt to fix the versioning issues I was having. All in all, we shouldn’t be using a package manager to install <i>another</i> package manager.
    
<h3> Installing NVM </h3>

<i>Note</i>: While this is a niche article for users with specific needs, I’d like to keep it as beginner-friendly as possible, and as such, I have included how to install Xcode’s developer tools and how to uninstall Node.js via Homebrew in case someone out there has already installed it and wishes to undo the process. Skip the first step if you already have either Xcode or developer tools installed on your machine. 

1. Fire up the terminal and type:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mazcj2b5ier8bhwshqek.png)

2. Uninstall any instances of Node.js via Homebrew. Type the following in the same order as they appear:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/x3cnow8x4ux4q6vbhl81.png)

3. Use <i>touch</i> to create a “bash-profile” on your machine. Type: 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/wk7kvk7dwl0xrplmy7yq.png)

4. Download NVM via <i>wget</i>. Type:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/z8b62wlq6f2f466xszp2.png)

5. Refresh terminal's command path. Type:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/omqhh1cj9x9tn5a9tyzz.png)

6. Check which version of NVM got installed. This should produce an output with the version number. Type:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7xe1x2fs0sm83vlohi4l.png)

<h3> Installing Node.js Using NVM </h3>

1. First, let's list all versions available for download. This should produce an output with all Node.js versions. Type:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7xmp7e9djajiuyhvxd63.png)

2. To install the latest stable version, as of early 2020, type:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/8ae31qz2g0v2gm9w1u4s.png)

3. Finally, let's check which versions of both Node.js and NPM are currently being used. Type:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/24bv2l7juf1rmg3j1o3e.png)
 
<h3> Conclusion </h3>
With Node.js and NVM installed, you can now reliably use NPM and switch between its versions in a more efficient way. Whether you're working on that new ReactJS app or else, the NPM community has certainly got you covered with Node packages that can help you in your journey. Happy coding!