Pip install homebrew-npm-noob. Brew install zmwangx/npm-noob/noob Usage $ noob -help usage: noob -h -w -t TAP -v -debug package Generate a Homebrew formula for an npm package. By default the generated formula is printed to stdout. If -w, -write is specified, the formula is directly written to the specified tap, or homebrew/core. If you're a Homebrew user and you installed node via Homebrew, there is a major philosophical issue with the way Homebrew and NPM work together. If you install node with Homebrew and then try to do npm update npm -g, you may see an error like this.
Development is picking pace, and Node.js is shipping out a new version frequently. It is nice to have the latest version at hand in your development environment to test out new features.
There are a few ways to install Node.js. One of the obvious ones is to download the installer from nodejs.org. However, you might not want to be downloading a new installer every time there's a new version out.
Here are few alternative ways to update to the latest version of Node.js on a Mac.
Nvm
Nvm is a script-based node version manager. You can install it easily with a curl and bash one-liner as described in the documentation. It's also available on Homebrew.
Assuming you have successfully installed nvm. The following will install the latest version of node.
The last option installs all global npm packages over to your new version. This way packages like mocha and node-inspector keep working.
N
N is an npm-based node version manager. You can install it by installing first some version of node and then running npm install -g n
.
Assuming you have successfully installed n. The following will install the latest version of node.
Homebrew
Homebrew is one of the two popular package managers for Mac. Assuming you have previously installed node with brew install node
. You can get up-to-date with formulae and upgrade to the latest Node.js version with the following.
MacPorts
MacPorts is the other package manager for Mac. The following will update the local ports tree to get access to updated versions. Then it will install the latest version of Node.js. This works even if you have a previous version of the package installed.
There also exists nodejs
alternative to nodejs-devel
that follows the long term support line.
In this tutorial we will learn to install NodeJS and NPM on Mac using Homebrew.
Step 1: Install Homebrew
Homebrew is 'The missing package manager for macOS'.
Open terminal and type the following command.
This will install Homebrew on your Mac. To check the version type the following command.
Output
Why use Homebrew to install NodeJS?
If you are installing NodeJS via the installer from https://nodejs.org/ then you have to use sudo
to make sure that it installs correctly. After that you have to make changes in your system $PATH
by adding the path of the node executable. And if you want to uninstall node then you have track all the files that were created and get rid of them. In short its a long process.
That's why Homebrew is used. It makes the job easy. It will install/uninstall Node easily.
Step 2: Install Node via Homebrew
In the terminal type the following command to install Node.
Homebrew Npm Install
If everything installed successfully then you can type in the following command in the terminal to check the Node and NPM version.
Possible issues/errors that may occur
If you look above you will see that we have some issues.
So, in terminal type the following command.
We also got an error 'Error: The `brew link` step did not complete successfully'.
So, type the following command.
Output
The above output says:
You may want to remove it:
rm '/usr/local/share/man/man1/node.1'
So, use the following command.
Now, to list all files that would be deleted use the following command.
Homebrew Update Npm
Output
Now we got the Error: Could not symlink share/systemtap/tapset/node.stp
/usr/local/share/systemtap/tapset is not writable.
To fix this we have to change the username and group of the systemtap directory.
Type the following command in the terminal.
Output
Now, run the --overwrite --dry-run command again.
Output
Now, we got the Error: Could not symlink lib/dtrace/node.d
/usr/local/lib/dtrace is not writable.
To fix this we have to change the username and group of the dtrace directory.
In the terminal type in the following command.
Output
Now, run the --overwrite --dry-run command again. Hopefully you will get no error. So, its time to run the --overwrite command.
Output
Congratulation! You have successfully installed NodeJS and NPM on your Mac via Homebrew.