168

I tried to install twitter bower on my Mac, and I used

npm install bower -g

Then I tried bower --help, and the output was bower command not found. Why is that?

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
Amo Wu
  • 2,507
  • 2
  • 18
  • 22
  • 2
    What is the output from `npm install`? Did it fail? Did it install bower to some location not on your `PATH`? – jches Sep 11 '12 at 13:43
  • possible duplicate of ["command not found" after installation](http://stackoverflow.com/questions/15846076/command-not-found-after-installation) – Sindre Sorhus Jul 17 '13 at 23:28
  • 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 06:45

5 Answers5

375

Just like in this question (npm global path prefix) all you need is to set proper npm prefix.

UNIX:

$ npm config set prefix /usr/local
$ npm install -g bower

$ which bower
>> /usr/local/bin/bower

Windows ans NVM:

$ npm config set prefix /c/Users/xxxxxxx/AppData/Roaming/nvm/v8.9.2
$ npm install -g bower

Then bower should be located just in your $PATH.

Stéphane GRILLON
  • 11,140
  • 10
  • 85
  • 154
Petr Joachim
  • 3,970
  • 1
  • 13
  • 9
  • 1
    I would like to add that this is not the most correct answer if you work with multiple projects. Bower should be installed in the `node_modules`locally from `package.json` and not globally, since different projects can use different versions (that's the whole point of `npm`). The real problem is that the system is not able to find the local bower executable. – Bruno Finger Oct 10 '16 at 08:08
  • @BrunoFinger: When installing bower to global scope, that answer is not solving the problem. However using local node packages might be a better way of dealing with project specific tools. – Petr Joachim Dec 05 '16 at 07:37
  • I think if npm prefix is set to /usr/local, npm install -g will fail without sudo. – Guo Jun 13 '18 at 15:02
  • We don't recommend using Bower for new projects. Please consider Yarn and Webpack or Parcel. – Daniel Aug 13 '18 at 14:55
66

I am almost sure you are not actually getting it installed correctly. Since you are trying to install it globally, you will need to run it with sudo:

sudo npm install -g bower
KyleMit
  • 30,350
  • 66
  • 462
  • 664
  • 3
    That is how bower must be installed, otherwise it will be just installed on the folder where you executed the command. -g means global and it also creates the required links for modules that can be executed as system commands, bower, grunt-cli, even npm are clear examples of this. –  Dec 13 '13 at 18:00
  • Dont install with sudo! Just use brew doctor and make the fixes that brew doctor suggests and then you wont need to use sudo! – djangofan Jun 23 '17 at 17:56
7

Alternatively, you can use npx which comes along with the npm > 5.6.

npx bower install

Kuldeep Saxena
  • 1,803
  • 1
  • 14
  • 17
  • 1
    This should be the accepted answer. You shouldn't ever install global modules with npm. – chovy Sep 27 '19 at 16:03
4

This turned out to NOT be a bower problem, though it showed up for me with bower.

It seems to be a node-which problem. If a file is in the path, but has the setuid/setgid bit set, which will not find it.

Here is a files with the s bit set: (unix 'which' will find it with no problems).

ls -al /usr/local/bin -rwxrwsr-- 110 root nmt 5535636 Jul 17 2012 git

Here is a node-which attempt:

> which.sync('git')
Error: not found: git

I change the permissions (chomd 755 git). Now node-which can find it.

> which.sync('git')
'/usr/local/bin/git'

Hope this helps.

user3112929
  • 2,411
  • 2
  • 12
  • 5
3

I am using node version manager. I was getting this error message because I had switched to a different version of node. When I switched back to the version of node where I installed bower, this error went away. In my case, the command was nvm use stable

bee
  • 59
  • 3