Skip to main content
Step 1: Install Homebrew

Homebrew is the missing package manager for macOS.

As per the Homebrew site, paste the following in a macOS Terminal prompt.

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

This acton will install Homebrew on your OSX.  Using the following command you can check the brew version

$ brew -v

 

Step 2: Install Node via Homebrew

Type following command to install node

$ brew install node

Check the Node and NPM version using the node -v command

$ node -v v15.8.0

Check the npm version using the npm -v command

$ npm -v 7.5.0

If both of these commands are showing a version installed, then you’re done.

 

To install specific Node version

1. To unlink from current version

$ brew unlink node

2. Install any version

$ brew install node@14 //To install version 14

To link installed version

$ brew link node@14

To check your current node version, Type

$ node -v

 

How to Update Node and NPM

New versions of Node and NPM come out frequently. You can use Homebrew to update the software it installs.

Make sure Homebrew has the latest version of the Node package. In Terminal type

brew update

Upgrade Node:

brew upgrade node

 

Errors

Homebrew npm install: could not symlink
Could not symlink share/doc/node/gdbinit
Target /usr/local/share/doc/node/gdbinit
already exists. You may want to remove it:
  rm '/usr/local/share/doc/node/gdbinit'

 

If you attempt the above command, most likely you will have received permission denied response.

Due to running the sudo command, several files and directories in /usr/local are now owned by root.  To correct this situation, take back ownership of all of the files and directories under /usr/local:

sudo chown -R $(whoami) $(brew --prefix)/*

Once that is done then run

brew doctor

​​​​​​​

Attempting to install node
brew install node

Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/icu4c-67.1.big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/114cce72e22c5eb713f56b9f91a076b2f2d593015
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/node-15.8.0.big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/17b8ff702a73a9f8876ba4eb30c434f2413aa11f1
######################################################################## 100.0%
==> Installing dependencies for node: icu4c
==> Installing node dependency: icu4c
==> Pouring icu4c-67.1.big_sur.bottle.tar.gz
==> Caveats
icu4c is keg-only, which means it was not symlinked into /usr/local,
because macOS provides libicucore.dylib (but nothing else).

If you need to have icu4c first in your PATH, run:
  echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.zshrc

For compilers to find icu4c you may need to set:
  export LDFLAGS="-L/usr/local/opt/icu4c/lib"
  export CPPFLAGS="-I/usr/local/opt/icu4c/include"

For pkg-config to find icu4c you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig"

==> Summary
🍺  /usr/local/Cellar/icu4c/67.1: 258 files, 71.8MB
==> Installing node
==> Pouring node-15.8.0.big_sur.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/node
Target /usr/local/bin/node
already exists. You may want to remove it:
  rm '/usr/local/bin/node'

To force the link and overwrite all conflicting files:
  brew link --overwrite node

To list all files that would be deleted:
  brew link --overwrite --dry-run node

Warning: The post-install step did not complete successfully
You can try again using:
  brew postinstall node

Observing the last note, regarding brew postinstall node... I attempted to run this command

brew postinstall node
==> Postinstalling node
Warning: The post-install step did not complete successfully
You can try again using:
  brew postinstall node

However, it also failed.  So I had to remove what had been in part installed on the Mac and begin the process again.  Ensuring that there were no directories with to node.  Including

rm /usr/local/bin/node

rm /usr/local/includes/node

brew uninstall node # or `brew uninstall --force node` which removes all versions ​​​​​​​

Run the brew clean up command before next executing the rm command

brew cleanup ​​​​​​​

rm -f /usr/local/bin/npm /usr/local/lib/dtrace/node.d

rm -rf ~/.npm

Check that all instances have been removed.  Once you have completed this check, go back to step 2 near the top of the screen and install node.

 

How a successful installation process will look in your shell program

$ brew install node

Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/node-15.8.0.big_sur.bottle.tar.gz
Already downloaded: /Users/{your name}/Library/Caches/Homebrew/downloads/9bf57615654f850ea19d76c53dee4b63bc00f11a242813b95b8450e45942a12b--node-15.8.0.big_sur.bottle.tar.gz
==> Pouring node-15.8.0.big_sur.bottle.tar.gz
🍺  /usr/local/Cellar/node/15.8.0: 3,336 files, 55.9MB
$ node -v

v15.8.0

$ npm -v

7.5.0

Related articles

Andrew Fletcher09 Oct 2023
npm package management
A summary of Node package commandsShort cut commandsnpm install <package>npm i <package>npm install --save <package>npm i -S <package>npm install --save-dev <package>npm i -D <package>npm install --global <package>npm i -G <package>npm testnpm...
Andrew Fletcher13 Feb 2023
brew changing PHP versions on OSX
Installing PHP on OSX and it installed PHP 8.2.x.  However, for my applications I need to run 8.1.x.  How do you switch the current PHP version?   Current version Check the current PHP version by executing the command php -v Response: PHP 8.2.2 (cli) (built: Feb ...
Andrew Fletcher27 Dec 2022
OSX brew regular commands
Regular commands for brew   Brew update This updates Homebrew itself.  Keeping Homebrew current with the command brew update.  Note, before running this command, it can take some time (if you haven't run it recently).  It is highly recommended that you run the update...