Brew Npm

Posted on  by admin

5 tips for publishing your first npm package Are you ready to share your code with the world? This post will help you avoid some common pitfalls when publishing a package to npm. Brew 下 安装node 和 npm. 其实npm是nodejs的包管理器(package manager)。我们在Node.js上开发时,会用到很多别人已经写好的javascript代码,如果每当我们需要别人的代码时,都根据名字搜索一下,下载源码,解压,再使用,会非常麻烦。. Installing npm with Homebrew never seemed to work properly but I never knew why. Now I still don't but have them installed:) I had to use SGD1953's tip and do 'sudo rm -rf /.npm' before installing npm.

By Panu Pitkamaki

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 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 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 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 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 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.

Question or issue on macOS:

I am trying to use homebrew as much as possible. What’s the suggested way to install the following on OS X?

and hopefully supports development for:

How to solve this problem?

Solution no. 1:

  1. Using homebrew install nvm:

    Add the last command to the .profile, .bashrc or .zshrc file to not run it again on every terminal start. So for example to add it to the .profile run:

    If you have trouble with installing nvm using brew you can install it manually (see here)

  2. Using nvm install node or iojs (you can install any version you want):

  3. npm is shipping with node (or iojs), so it will be available after installing node (or iojs). You may want to upgrade it to the latest version:

    UPD Previous version was npm update -g npm. Thanks to @Metallica for pointing to the correct way (look at the comment bellow).

  4. Using npm install ionic:

  5. What about ngCordova: you can install it using npm or bower. I don’t know what variant is more fit for you, it depends on the package manager you want to use for the client side. So I’ll describe them both:

    1. Using npm: Go to your project folder and install ng-cordova in it:

    2. Using bower: Install bower:

      And then go to your project folder and install ngCordova in it:


  1. Some commands may require superuser privilege
  2. Short variant of npm install some_module is npm i some_module

Solution no. 2:

2019 update: Use NVM to install node, not Homebrew

In most of the answers , recommended way to install nvm is to use Homebrew

Do not do that

At Github Page for nvm it is clearly called out:

Homebrew installation is not supported. If you have issues with
homebrew-installed nvm, please brew uninstall it, and install it using
the instructions below, before filing an issue.

Use the following method instead

The script clones the nvm repository to ~/.nvm and adds the source line to your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).

And then use nvm to install node. For example to install latest LTS version do:

Clean and hassle free. It would mark this as your default node version as well so you should be all set

Solution no. 3:

I’m using n (Node version management)

You can install it in two ways


You can switch between different version of node and io. Here’s an example from my current env when I call n without params:


Solution no. 4:

I’m super late to this but I didn’t like the other answers

Installing Homebrew

For brew run

Installing node & npm

You SHOULD NOT use brew to install node and npm.

I’ve seen a few places suggested that you should use Homebrew to install Node (like alexpods answer and in this Team Treehouse blog Post) but installing this way you’re more prone to run into issues as npm and brew are both package managers and you should have a package manager manage another package manager this leads to problems, like this bug offical npm issues Error: Refusing to delete: /usr/local/bin/npm or this Can’t uninstall npm module on OSX

You can read more on the topic in DanHerbert’s post Fixing npm On Mac OS X for Homebrew Users, where he goes on to say

Also, using the Homebrew installation of npm will require you to use sudo when installing global packages. Since one of the core ideas behind Homebrew is that apps can be installed without giving them root access, this is a bad idea.

For Everything else

I’d use npm; but you really should just follow the install instruction for each modules following the directions on there website as they will be more aware of any issue or bug they have than anyone else

Solution no. 5:

If you have previously installed node using brew, then you will have a bunch of extra files that you should clean up before installing node “the right way”. Plus, I had to add a few settings to my startup script to make things work smoothly.

I wrote a script to make this easy.

I wrote a short article here that details why this is “the right way”.

If you need to install iojs, do so using nvm like this:

To install brew, just see its home page.

See alexpods answer for the rest.

Solution no. 6:


You should install node.js with nvm, because that way you do not have to provide superuser privileges when installing global packages (you can simply execute “npm install -g packagename” without prepending ‘sudo’).

Brew is fantastic for other things, however. I tend to be biased towards Bower whenever I have the option to install something with Bower.


Solution no. 7:

I agree with noa — if you need to have multiple versions of node, io.js then brew is not the appropriate solution.

Brew Npm Version

You can help beta-test io.js support in nvm:

If you just want io.js and are not switching versions, then you can install the binary distribution of io.js from ; that includes npm and you will not need nvm if you are not switching versions.

Remember to update npm after installing: sudo npm install -g [email protected]

Brew Npm 6

Solution no. 8:

Here’s what I do:

Brew npm 7

No Homebrew for this one.

nvm soon will support io.js, but not at time of posting:

Then install everything else, per-project, with a package.json and npm install.

Solution no. 9:

For install with zsh and Homebrew:

Homebrew Vs Npm

Then Add the following to ~/.zshrc or your desired shell
configuration file:

Then install a node version and use it.

Brew Npm Mac

Hope this helps!