Skip to content

Instantly share code, notes, and snippets.

@fscm
Last active February 1, 2022 17:25
Show Gist options
  • Save fscm/91134520771b7f06cf7145ea8c3091ad to your computer and use it in GitHub Desktop.
Save fscm/91134520771b7f06cf7145ea8c3091ad to your computer and use it in GitHub Desktop.
[macOS] Install Node.js JavaScript runtime

[macOS] Install Node.js JavaScript runtime

Instructions on how to install the Node.js JavaScript runtime on macOS.

Uninstall

First step should be to unsinstall any previous Node.js installation. This step can be skipped if no Node.js version was previously installed.

This will completelly remove any Node.js previously installed. If you which to keep the user modules installed with npm you should skip the last set of commands.

To uninstall any previous Node.js installations use the following commands:

sudo rm -rf /usr/local/{lib,include}/{node,node_modules}
sudo rm -rf /usr/local/share/doc/node
sudo rm -f /usr/local/bin/{node,node-debug,node-gyp}
sudo rm -f /usr/local/share/man/man1/{node,npm}*
sudo rm -f /usr/local/lib/dtrace/node.d
sudo rm -f /usr/local/share/systemtap/tapset/node.stp

(these are your npm settings, don't delete this if you plan on re-installing Node.js)

rm -rf ~/{.npmrc,.npm,.node-gyp,.node_repl_history}

Prerequisites

macOS Command Line Tools need to be installed on your local computer.

To install the Command Line Tools run the following command:

xcode-select --install

Install

The Node.js JavaScript runtime can be obtained here. Copy the link for the package version that you want to install from there.

Get the Node.js installer package using the following commands:

mkdir ~/Downloads/Node
(cd ~/Downloads/Node && curl --silent --location --retry 3 --remote-name "https://nodejs.org/dist/v15.1.0/node-v15.1.0.pkg")

Run the installer package using the following command:

sudo installer -pkg ~/Downloads/Node/node*.pkg -target /

Verify

Open a new terminal window and check if the Node.js JavaScript programming language is installed:

node --version
npm --version

Clean up

After installing the Node.js JavaScript runtime you can remove the downloaded installation package using the following command:

rm -rf ~/Downloads/Node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment