44

I seem to be getting the following when I execute npm install bower -g

/usr/local/share/npm/bin/bower -> /usr/local/share/npm/lib/node_modules/bower/bin/bower
bower@0.8.6 /usr/local/share/npm/lib/node_modules/bower

Unfortunately executing any of the bower commands returns -bash: bower: command not found

which npm returns /usr/local/bin/npm and running which node returns /usr/local/bin/node.

AncientSwordRage
  • 7,086
  • 19
  • 90
  • 173
Gray Ghost
  • 477
  • 1
  • 4
  • 9
  • Related posts - [bower is not recognised as an internal or external command](https://stackoverflow.com/q/27360710/465053) & [bower command not found windows](https://stackoverflow.com/q/21732447/465053) – RBT May 27 '18 at 07:39

11 Answers11

67

I assume you installed Node.js through Homebrew, which annoyingly puts installed npm binaries in a place that is usually not in a users path. All you have to do is to add /usr/local/share/npm/bin to your $PATH. You do that by adding export PATH=/usr/local/share/npm/bin:$PATH to your .bashrc/.bash_profile/.zshrc file.

Although I would rather uninstall the Homebrew installed Node.js and install it with the installer from nodejs.org which doesn't have this problem.

This problem is not Bower specific and will be noticeable with any globally installed Node.js binary, eg. grunt, uglify, jshint, etc.

Sindre Sorhus
  • 62,972
  • 39
  • 168
  • 232
  • 1
    LOL My Hero! thanks. Yeah, I installed it through homebrew. Everything is a fresh install on a new machine and homebrew seemed to be the easiest to get going with packages and dependencies. I'm also using Paul's dotfiles with the `.extra` file in my `~` to control paths. In my `.extra` file is now the line above with the `export PATH` line you outlined. `# PATH additions` `PATH=$PATH:~/.rvm/bin # ruby` `export PATH=/usr/local/bin:$PATH # local path` `export PATH=/usr/local/share/npm/bin:$PATH # Boom! Works now \m/` – Gray Ghost Apr 06 '13 at 13:23
  • 1
    I just wanted to add that I ended up uninstalling Node.js from the Homebrew installation and installed Node.js from the installer via the Node.js Website. This allowed me not having to add the PATH stuff mentioned previously resulting in a much cleaner install. – Gray Ghost Apr 07 '13 at 18:02
  • 8
    And I just wanted to add that on Windows 7, I had to add C:\Users\MyUsername\AppData\Roaming\npm to my path. – chris polzer May 07 '14 at 13:28
  • I installed Node through the `.pkg` installer from [nodejs.org](https://nodejs.org/en/download/) and it doesn't put npm binaries in my path either. As far as I can tell it puts them in `~/.npm-packages/bin/`, but never mentions you need to add this to your path. – David Moles Sep 07 '16 at 22:26
9

For users that are encountering issues with the installation in mac as shown in the official page, it seems that El Capitan is giving permission issues to install the package in that way:

npm install bower -g

The solution I've found to avoid the permission errors is using sudo (superuser do) to provide access for node to download the package like this:

sudo npm install bower -g

Hopefully this may help users having the same problem. :)

Lors
  • 91
  • 1
  • 2
6

I know this question has been answered and accepted long time ago. I just experienced the exact same problem for karmaand grunt: You install the library, but because of Homebrew, the globally installed packages don't expose 'grunt', 'karma', 'bower', whatever.

Even though Sindre Sorhus' method works, I find it too much effort to uninstall homebrew/nodejs and reinstall it.

Instead I used

npm install -g grunt-bower-cli

and same for the others:

npm install -g grunt-cli
npm install -g karma-cli

Grunt's documentation explains why you need this step:

This will put the grunt command in your system path, allowing it to be run from any directory.

Note that installing grunt-cli does not install the Grunt task runner! The job of the Grunt CLI is simple: run the version of Grunt which has been installed next to a Gruntfile. This allows multiple versions of Grunt to be installed on the same machine simultaneously.

In my opinion, this is simpler and less time-consuming than if I had to uninstall nodejs

Jesper Rønn-Jensen
  • 106,591
  • 44
  • 118
  • 155
  • I think this is the best approach. Sticking with Homebrew it's imperative to not have to keep track of all sort of installers over time... – Detro Jul 29 '14 at 10:29
6

If you have a 'non standard' installation, you need to find the node bin location location with:

npm config list

Then add the node bin location to your ~/.bash_profile

export PATH=<yourNodeBinLocation>:$PATH

Remember to open a new terminal to test, or source ~/.bash_profile

Bwyss
  • 1,736
  • 3
  • 25
  • 48
2

In Mac OS X add next row into your ~/.bash_profile

export PATH="$HOME/.node/lib/node_modules/bower/bin:$PATH"

And restart terminal or type:

source ~/.bash_profile

Anatolii Pazhyn
  • 1,442
  • 13
  • 7
1

If you used something other than Homebrew (yes, some of us actually did it weird) —like MacPorts, your $PATH could be funky. Binaries may be located in other areas: /opt/local/bin/grunt and possibly /opt/local/bin/npm

Additionally if you use MacPorts to install npm then subsequently install bower, the binary will not be located where you'd expect. It actually ends up in your home directory under .npm/lib/node_modules/bower/bin

Your $PATH should be adjusted in ~/.profile (Mac OS X) to add: $HOME/.npm/lib/node_modules/bower/bin

Source your Bash profile or open a new terminal window and it should be working.

1

i add this

export PATH=$HOME/.node/bin:$PATH

at the end (and new line) of my .bash_profile file( located in user folder). Save it. close and reopen terminal

Valix85
  • 773
  • 1
  • 9
  • 20
1

As of September 2016, the .pkg installer from nodejs.org arranges for installed packages to be under $HOME/.npm-packages/lib/node-modules, with symlinks in ~/.npm-packages/bin:

$ bower install
-bash: bower: command not found
$ which bower
$ export PATH=$PATH:~/.npm-packages/bin
$ which bower
/Users/dmoles/.npm-packages/bin/bower
David Moles
  • 48,006
  • 27
  • 136
  • 235
1

If all of the above doesn't work, or you don't seem to understand the answers provided to the question.

I suggest you run the installation commands on your system command prompt and not git-bash, especially if your are on windows 8 or 7.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
pelume_
  • 213
  • 2
  • 10
0

My problem was the Homebrew/node/npm bug found here - https://github.com/npm/npm/issues/3794

If you've already installed node using Homebrew, try:

npm update -gf

Or, if you want to install node with Homebrew and have npm work, use:

brew install node --without-npm
curl -L https://npmjs.org/install.sh | sh
YPCrumble
  • 26,610
  • 23
  • 107
  • 172
0

In centos 6.8

vi ~/.zshrc 

add three row below

export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:$PATH
export PATH=/usr/local/share/npm/bin:$PATH

and then

exec /bin/zsh 

or

exec /usr/bin/zsh

just work

Jeremy
  • 1