Installing NodeJS on macOS

After being a software engineer on windows platform for more than two decades, recently I switched over to MacBook and started to set it up as my primary development machine. One of the biggest challenges I faced were unavailability of a single (or max a couple) source(s) that could explain how to setup NodeJS on MacOS. After extensively searching on the internet and with several hits and trails, I was finally able to compile a “Hello World” NodeJS program on my new MacBook.

Based on what I have had to go through, I felt creating this doc for people like me and those who may come across similar situation.

Prerequisites:

Basic familiarity with Mac’s zsh terminal application: You will need to have some level of familiarity with zsh terminal app to install, verify and use NodeJS. Mac’s terminal app can be found under ‘Utilities’ inside ‘Applications’ folder.

Homebrew: There may be a few options, but Homebrew is one of the best ways to install NodeJS and NPM. Homebrew also protects you from security implications that are associated to using ‘sudo’ command. You can also use Homebrew to install things like git, ruby etc. on your mac.

Installing Homebrew on MacBook:

Open the terminal app.

Copy the following curl command into your terminal app:

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

It will start installing Homebrew and will ask for your Mac password to gain sudo access to proceed with installing Homebrew.

For more details on Homebrew, feel free to go to the Homebrew website: https://brew.sh/.

Please note that the Brew community continues to make enhancements to Homebrew and release frequent updates. To stay up to date with latest version of Homebrew, you can execute the following command on the terminal app: brew update.

Installing NodeJS and NPM:

Execute the following command on the mac terminal app: brew install node

After installation is complete, you can verify node and NPM using the following commands.

node -v

npm -v

These commands will give you the version numbers of Nodejs and NPM that are installed by Homebrew on your MacBook. These versions should mostly match with the latest LTS version on nodejs.org.

To stay up to date with latest LTS version of NodeJS, you can execute the following commands in your terminal app. These commands will update Homebrew and NodeJS to latest versions.

brew update

brew upgrade node

At this point, you should have latest version of NodeJS installed on your MacBook.

In the next article, we will get into setting up an IDE to start using NodeJS. There are tons of great options available, but I prefer to use ‘Visual Studio Code’ for most of my software development needs. Stay tuned!

Leave a comment