Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble with local install of bower [duplicate]

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.

like image 207
yiooxir Avatar asked Feb 23 '14 18:02

yiooxir


1 Answers

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.

like image 96
Whymarrh Avatar answered Nov 04 '22 20:11

Whymarrh