Skip to content

Instantly share code, notes, and snippets.

@rs77
Created December 9, 2022 21:32
Show Gist options
  • Save rs77/9be20a02eff169a308f4db6711a6de4f to your computer and use it in GitHub Desktop.
Save rs77/9be20a02eff169a308f4db6711a6de4f to your computer and use it in GitHub Desktop.
How to install NodeJS on Mac OS

The problem I have with NodeJS is having it automatically update itself. I don't want to have to re-install the direct downloadable file from NodeJS every time there's a patch update.

Wouldn't it be great to install it once, and when needed, run a command for it to automatically update?

Thankfully there is such an easy process: Homebrew for Mac

So here were the steps I undertook to be able to reinstall NodeJS back on to my computer:

Is NodeJS Already Installed?

Before you install node you may want to check if you already have it installed. To check if node is already on my machine run node -v in your terminal. This simple command checks the version number of the currently installed node module on your computer.

$ node -v
bash: node: command not found

If you have node installed, you should see a version number pop up underneath your command. Great, there's nothing more for you to do here! If though, you see the above, move on to the next step.

Install Homebrew

The quickest way to install NodeJS on your Mac is via Homebrew.

To install Homebrew check the latest instructions from their home page here.

Currently the command to run in terminal to install Homebrew is:

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

When you run this command from within your terminal window you may see some additional prompts, such as:

==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew
==> The following new directories will be created:
/opt/homebrew/bin
/opt/homebrew/etc
/opt/homebrew/include
/opt/homebrew/lib
/opt/homebrew/sbin
/opt/homebrew/share
/opt/homebrew/var
/opt/homebrew/opt
/opt/homebrew/share/zsh
/opt/homebrew/share/zsh/site-functions
/opt/homebrew/var/homebrew
/opt/homebrew/var/homebrew/linked
/opt/homebrew/Cellar
/opt/homebrew/Caskroom
/opt/homebrew/Frameworks
==> The Xcode Command Line Tools will be installed.

Press RETURN to continue or any other key to abort

To proceed with the installation of other necessary libraries that Homebrew needs, hit the RETURN key. If you see another prompt asking you to download XCode or XCode tools, then go into the App Store and install XCode first, before re-running the previous Homebrew installation script.

Finding available software

Downloading Command Line Tools for Xcode
Downloaded Command Line Tools for Xcode
Installing Command Line Tools for Xcode
Done with Command Line Tools for Xcode
Done.

As Homebrew installs itself on your machine, you will see additional prompts on how things are progressing. Soon the installation would have finished and you may be prompted to perform some additional actions within the terminal.

==> Next steps:
- Add Homebrew to your PATH in /Users/rds/.zprofile:
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/r/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run `brew help` to get started
- Further documentation: 
    https://docs.brew.sh

Homebrew Update

Before installing node, let's do a little housekeeping with Homebrew just to make sure our computer is updated and everything is in working order.

a) Check your system has the latest updates by running the command:

$ brew update

If you see Already up-to-date then you've got the latest updates on your machine. If not, you would have noticed a bunch of modules updated on your system.

b) Check your system is humming along well with no conflicts by running brew doctor:

$ brew doctor
Your system is ready to brew.

If you see Your system is ready to brew then your computer is ready to proceed. If not, please read through any of the instructions provided on how you can correct your modules.

Install NodeJS With Homebrew

Our final step is to simply run the command brew install node:

$ brew install node

You should see lots of action, and to check you've properly installed it, re-run our first command in terminal node -v:

$ node -v
v14.2.0

Now you're ready to use NodeJS.

Conclusion

Installing NodeJS is easily handled if done using the awesome package manager for Mac OS with Homebrew. While it main seem a little painful at first with all the extra installation of packages (etc), you will find as NodeJS upgrades their version it will be a lot easier to update with the help of Homebrew.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment