Setting Up Your Node Environment on Mac

Node is a runtime environment that allows Javascript to be run outside of a browser. You can think of runtime environments as a fancy way to say an environment in which we can run something. In this case, Javascript on your local machine outside of a browser. Before node, Javascript could only be run in browsers, since browers have Javascript intepreters embedded in them.

Now, setting up node is a pretty straight forward process. It involves first setting up a version manager known as nvm or "node version manager." This allows us to easily swap between node versions with a simple command line interface. Which is incredibly helpful when you work on various project which may use different node versions. Then, we'll install a version of node through nvm and then select it as our default. Let's jump in!

NVM Setup

nvm can easily be installed through the brew package manager. If you don't have brew, you can install it here. Or run the following:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once you have brew installed, install nvm by running:

brew install nvm

Once nvm is done installing, you may have to restart your terminal for it to be available in your shell. We can check that nvm installed correctly by simply running:

nvm

If it is installed and setup correctly, it should output a helpful guide with common commands and documentation.

Install a Node Version

If you ran nvm in the previous step, you may have noticed it shows you an example of how to install a version of node. How convenient!

Let's install node version 18.16.0. For you, this version is completely arbitrary, but it happens to my current node version. So, that's what we're running with. If you want to install a different one, swap out the version number.

nvm install 18.16.0

Selecting Your Node Version

Once the install is complete, we have to select the node version with nvm. In this case, we're going to set the default version.

nvm alias default 18.16.0

Now we can test that everything is setup correctly.

node --version

This should output 18.16.0, or whichever version you installed and set as your default. If it does, awesome job setting up node!