Installing Node.JS in Mac
Published: 2021-05-16 16:53:16

According to [nodejs.org](https://nodejs.org/en/), 
- <strong>Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.</strong> 🤯

Let me simplify this definition for you.

### So, What is a runtime?
You can think of the runtime as an environment that can run javascript code and also does have some extra functionality.

### And, what's a JavaScript Engine? 🤔
According to Wikipedia, a JavaScript engine is a computer program that executes JavaScript Code.

- V8 from Google is the most used JavaScript engine. 
- SpiderMonkey was developed by Mozilla.
- Chakra is the engine of the Internet Explorer browser 

---

## Installing Node.JS

- Navigate to [nodejs.org](https://nodejs.org/en/)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhjs2n63ezae1cw3f6ga.png)

The node team always gives us two main versions of node runtime :

- <u><strong>LTS ( Long Term Support )</strong></u>: Stability and Code won't break ( No bugs )

> 💡 Use LTS if you're working on some app and want to deploy it within a few weeks.

- <u><strong>Current ( Latest Features )</strong></u>: No stability

> 💡 Use the Current version if you're working on an app that will take at least a year to complete and push to production.

You can find the scheduled releases here for node : [https://nodejs.org/en/about/releases/](https://nodejs.org/en/about/releases/)

The simplest way to install Node.JS is to download the LTS or Current Version installer for your operating system. 

Download the installer from https://nodejs.org/en/download/ and then open it.

You'll get something like this :
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jrdrcx7nwt02zzr8r7ht.png)
- Click on continue
- Agree to the license and follow the steps.

To check whether node.js is installed :
After the installation is completed, Open Terminal App in your Mac and type :

`node --version` or `node -v`. 

These commands will return the version of node.js installed in your mac.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rue83j8nqwivr25p0pxq.png)

---


You can also install node.js via package managers like <u>nvm</u>.

<strong>nvm</strong> stands for node version manager and is used to have multiple versions of node installed at the same time and it allows us to install, uninstall, switch version, etc.

To install node.js via nvm, we should first install nvm in our mac.

### Installing nvm(node version manager):
 
Copy the install script from  [https://github.com/nvm-sh/nvm#installation-and-update](https://github.com/nvm-sh/nvm#installation-and-update) and paste it in the terminal.
 
Close and reopen the terminal after nvm is successfully installed.

Enter `command -v nvm` in terminal. If you see nothing listed, then this means nvm is not loaded into the shell. To fix this:

1. Check if we have a `~/.bash_profile` file.

2. If we have the file then open it in the nano text editor with the command `nano ~/.bash_profile`. 
Otherwise, create the file with the command `touch ~/.bash_profile` and open it.

3. Add `source ~/.bashrc` at the bottom of the `~/.bash_profile` file. Save and close the editor.

4. Type `source ~/.bash_profile` in the terminal. This will re-run the bash profile

- Now after nvm is successfully installed and loaded. We can install the node now.

- Open [https://nodejs.org/en/](https://nodejs.org/en/) and figure out the node version you want to install.

- Now, type `nvm install <version>` to install the node version. 

For example, if you want to install, node version 14.15.1. Run `nvm install 14.15.1` in the terminal.

- `nvm install node` will install the latest node version.
- `nvm use <version>` - to use a specific node version.

---