5

I installed bower locally in project, creating a folder 'node_modules' and 'bower' in it. then I run bower on the command line:

$ bower
bower: команда не найдена (command not found)

Why is this? if I install bower globally everything works correctly.

meawoppl
  • 2,714
  • 1
  • 23
  • 30
yiooxir
  • 327
  • 3
  • 7
  • 1
    If you install bower globally you will be able to use the `bower` command. Although you can also use the locally installed bower like so: `./node_modules/bower/bin/bower install` – Jason Feb 23 '14 at 18:17
  • Yep, install it globally with `npm install -g bower` – Bojangles Feb 23 '14 at 18:17

1 Answers1

8

How to install Bower (from the docs):

npm install -g bower

The important part is the -g flag, as that informs npm to install it "globally". This means that npm will create a symlink to the bower binary* in your Node.js binaries folder (which is in your PATH). This allows your shell (be it Bash, zsh, csh, etc.) to find the command.

Why won't it work if you run npm install bower?

Just running npm install bower installs the given package into the current folder under node_modules/{package}. If you do this and try running bower from the command line, your shell won't know where to find the bower command because it is not in your PATH (hence the "command not found" error).

As @Jason noted in the comments, you can explicitly run the bower binary* by running ./node_modules/bower/bin/bower. When run like this, your shell will know where to find the command. You can, if needed, alias that to something shorter:

alias bower="./node_modules/bower/bin/bower"

* I use the word binary extremely loosely. It's more a file marked as being executable with a shebang atop it.

Whymarrh
  • 13,139
  • 14
  • 57
  • 108
  • Oddly, I get this error when I perform these instructions: `bower EINVALID The name has to end with a lower case character from a to z`. *EDIT*: To solve this, all I needed was a bower.json file with at least the 'required' fields completed. – Con Antonakos Jun 04 '15 at 16:59