17

How do I install bower using package.json and npm?

I have my package.json file setup like so..

{
    "name": "myprogramname",
    "version": "0.0.1",
    "devDependencies": {
        "bower": "1.2.6"
        //other dependencies are listed as well
    }
}

from the command line I run

npm install

It installs all of my dependencies in devDependencies except bower. Any reason for this?

Also,

which bower

returns nothing

Brian Bolton
  • 3,633
  • 8
  • 35
  • 43
  • 5
    @mpm That does work, but it would be nice to have it in package.json so that other devs checking out my branch could install everything with just npm install. – Brian Bolton Feb 19 '14 at 20:37

2 Answers2

18

Npm did actually install Bower but not globally. If you check your node_modules/ directory, it should be there.

Therefore, it IS accessible for other developers at this path:

node_modules/bower/bin/bower
Aurélien Thieriot
  • 5,853
  • 2
  • 24
  • 25
  • 5
    Also accessible via `node_modules/.bin/bower`. [npm run](https://docs.npmjs.com/cli/run-script) adds this `.bin/` to the PATH, so you can avoid dealing with the exact path by writing the commands you'll need in [scripts section](https://docs.npmjs.com/misc/scripts) and using npm run. – Beni Cherniavsky-Paskin Jun 08 '15 at 12:00
  • 2
    A great way to run `bower install` right after `npm install` was described [here.](http://stackoverflow.com/a/18591690/697625) – quasiyoke Dec 04 '15 at 21:07
1

A neater way to use a local install of bower is shown here.

Basically you need to use "npm run bower install" instead of "bower install" if you install bower through NPM locally and don't have it installed globally on your computer.

kiml42
  • 638
  • 2
  • 11
  • 26
  • I liked this approach for running builds on multiple machines where I didn't want to have to worry about any box config besides installing Node. – RustyTheBoyRobot May 15 '18 at 16:54