Instructions on how to install the Node.js JavaScript runtime on macOS.
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}
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
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 /
Open a new terminal window and check if the Node.js JavaScript programming language is installed:
node --version
npm --version
After installing the Node.js JavaScript runtime you can remove the downloaded installation package using the following command:
rm -rf ~/Downloads/Node