Installing Node.js

Install Homebrew

Homebrew is an excellent package manager for MacOS-specific programs. It essentially gives you a way to install certain programs (usually developer-y ones) directly from the command line. It's similar to how NPM or Bower works.

To install Homebrew:

  • Head to the homebrew home page
  • Follow the instructions by copying/pasting the bash command into your terminal (from any directory, doesn't matter where).

Install NVM

NVM is the Node Version Manager, which makes installing and switching between multiple release versions of Node.js really easy. We'll use the freshly-installed Homebrew to install nvm:

From terminal (from any directory):

brew install nvm  

Once that completes, follow the instructions that print to the screen:

  • Run mkdir ~/.nvm (again, from anywhere in terminal)
  • Use a text editor (Vi or Nano would work well) to open (or create, if it doesn't exist yet) a file called .bash_profile inside your home directory:
vi ~/.bash_profile  

Add the 2 lines to the bottom of the .bash_profile file:

export NVM_DIR="$HOME/.nvm"  
. "/usr/local/opt/nvm/"

If you used Vi to add this, you can save and quit the file easily by hitting the "escape" key to exit out of insert mode, then hold "shift" and press "Z" twice to save and quit.

Run source ~/.bash_profile to re-run all the commands in that file, and now you should be able to run nvm --version and see a version number pop up. Congrats!

Use NVM to install Node.js and the Node Package Manager (NPM)

Head to and check what the latest stable version of Node.js is. You won't download it from here. You just need to know what the latest stable version ("Recommended for most users") is.

At the time of writing this post, the latest stable version is 8.9.4. Now head back to your terminal and type:

nvm install 8.9.4 (or whatever version you found from the site in the "Recommended..." green box.)  

Once that completes, you should be able to type node --version and npm --version and have version numbers pop up.

You're done! Enjoy JavaScript from the command line :)

Updating to new versions of node

NVM makes updating your node version very easy. If a newer version (let's say 8.10) is release, you can simply type nvm install 8.10 (or whatever the version number is) and you'll be updated to a newer version of node. The old versions are maintained on your machine, and can be switched to easily by entering nvm use 8.9.4, which will switch you back to that specific past version. This is useful if you have a past project that is perhaps broken on newer versions of node and you haven't yet had a chance to update the code to reflect changes that need to be made.