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.