Setting up a Node JS environment in macOS

Setting up a Node JS environment in macOS

Introduction

Developers can code and run simple interactive websites featuring vanilla Javascript code on browsers. Beyond that, there's a need to install a specialized node JS development environment.

Such a development environment offers command-line tools for developing and debugging more nuanced Javascript node server apps and Javascript framework applications such as React JS, Vue JS, and Angular JS.

In light of that, this guide explains the steps necessary to install a Node JS environment in x86 apple computers with macOS Version 10.15 (Catalina) or later. Therefore, update your macOS if necessary.

Prerequisite tools

Install Homebrew

Homebrew is a macOS package manager which allows quick installation of other programs. You might have Homebrew in your system already.

If running the command brew help results in a list of brew commands, then it is already installed, otherwise, follow the installation instructions below to perform the installation.

  1. Go to applications and open the terminal.

  2. Copy and paste this command /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" and press the Enter key.

  3. Patiently follow the subsequent installation prompts and close the terminal when done.

  4. Confirm a successful install by running brew help to see if brew commands pop up.

Install Zsh: The New macOS standard shell

Zsh comes as a built-in package with the latest macOS versions.

How can one check if Zsh is already installed?

  1. Open the terminal.

  2. Type the command echo $SHELL and press Enter.

  3. If the output is /usr/local/bin/zsh or /bin/zsh, then it's already installed.

If there's no such output as in step 3 above, proceed to run the following commands in the Terminal:

  1. Key in brew install zsh then press Enter.

  2. Next, type the command echo /usr/local/bin/zsh | sudo tee -a /etc/shells, then press Enter. Key in the password if requested.

  3. Next, type in chsh -s /usr/local/bin/zsh and press Enter.

  4. Now close the terminal.

  5. Reopen the Terminal. If you're greeted with the message that starts "This is the Z Shell configuration function for new users...", enter 0 and press Enter. Zsh installation should now be complete.

Handling installation errors. The following error may pop up on reopening the Terminal:
zsh compinit: insecure directories, run compaudit for list. Ignore insecure directories and continue [y] or abort compinit [n]?

To resolve it: press y and run the command:

compaudit | xargs chmod g-w

Close the Terminal and reopen it. The error should now be resolved.

The Node JS installation

With pre-requisite tools installed, now it's time to install the node version manager and node js runtime environment.

Install Node Version Manager (NVM)

Node version manager (NVM) allows the download, installation, and management of multiple Node.js versions.

  1. Launch Terminal.

  2. Type in curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | zsh and press the Enter key.

  3. Close the Terminal.

  4. Reopen the Terminal and type in nvm and press the Enter key. The terminal should output a long message terminating with the line: "to remove, delete, or uninstall nvm..." If this is the case, then the NVM installation is successful.

Install Node JS

Once NVM installation is complete, installing NodeJS happens in only a few steps listed below:

  1. Open the Terminal.

  2. Key in nvm install node then press Enter.

  3. Key in nvm list and press Enter. This should output a list of node versions in the format of "v16.18.1" - this may be a higher or lower number. Such a list marks a successful node JS installation.

Conclusion

This article has explained the steps necessary to install a Node JS development environment on x86 Apple computers with macOS Version 10.15 or later.

The first step is to install Homebrew, a macOS package manager, which allows for quick installation of other programs. Installing it can be done by copying and pasting the provided commands into the terminal and following the prompts that arise.

The next step is to install Zsh, the new macOS standard shell, which may already be built into the latest macOS versions. To install Zsh, run the series of commands provided.

Once the pre-requisite tools are installed, Node Version Manager (NVM) is installed, followed by the installation of Node JS.

In all, commands are provided to verify the successful installation of Homebrew, Zsh, NVM, and Node JS. I hope you have found this article helpful.