node.js Bower:安装后“找不到命令”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15846076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bower: "command not found" after installation
提问by Gray Ghost
I seem to be getting the following when I execute npm install bower -g
我在执行时似乎得到以下信息 npm install bower -g
/usr/local/share/npm/bin/bower -> /usr/local/share/npm/lib/node_modules/bower/bin/bower
[email protected] /usr/local/share/npm/lib/node_modules/bower
Unfortunately executing any of the bower commands returns -bash: bower: command not found
不幸的是,执行任何 bower 命令都会返回 -bash: bower: command not found
which npmreturns /usr/local/bin/npmand running which nodereturns /usr/local/bin/node.
which npm返回/usr/local/bin/npm和运行which node返回/usr/local/bin/node。
回答by Sindre Sorhus
I assume you installed Node.js through Homebrew, which annoyingly puts installed npm binaries in a place that is usually not in a users path. All you have to do is to add /usr/local/share/npm/binto your $PATH. You do that by adding export PATH=/usr/local/share/npm/bin:$PATHto your .bashrc/.bash_profile/.zshrc file.
我假设您通过 Homebrew 安装了 Node.js,这很烦人地将安装的 npm 二进制文件放在通常不在用户路径中的位置。您所要做的就是添加/usr/local/share/npm/bin到您的 $PATH 中。你可以通过添加export PATH=/usr/local/share/npm/bin:$PATH到你的 .bashrc/.bash_profile/.zshrc 文件来做到这一点。
Although I would rather uninstall the Homebrew installed Node.js and install it with the installer from nodejs.orgwhich doesn't have this problem.
虽然我宁愿卸载 Homebrew 安装的 Node.js 并使用nodejs.org的安装程序安装它,但它没有这个问题。
This problem is not Bower specific and will be noticeable with any globally installed Node.js binary, eg. grunt, uglify, jshint, etc.
这个问题不是 Bower 特有的,对于任何全局安装的 Node.js 二进制文件都会很明显,例如。咕噜、丑化、jshint 等。
回答by Lors
For users that are encountering issues with the installation in mac as shown in the official page, it seems that El Capitan is giving permission issues to install the package in that way:
对于在 mac 中遇到安装问题的用户,如官方页面所示,El Capitan 似乎提供了以这种方式安装软件包的权限问题:
npm install bower -g
npm install bower -g
The solutionI've found to avoid the permission errors is using sudo(superuser do) to provide access for node to download the package like this:
我发现避免权限错误的解决方案是使用sudo(超级用户做)为节点提供访问权限以下载这样的包:
sudo npm install bower -g
sudo npm install bower -g
Hopefully this may help users having the same problem. :)
希望这可以帮助遇到相同问题的用户。:)
回答by Jesper R?nn-Jensen
I know this question has been answered and accepted long time ago. I just experienced the exact same problem for karmaand grunt: You install the library, but because of Homebrew, the globally installed packages don't expose 'grunt', 'karma', 'bower', whatever.
我知道这个问题很久以前就已经得到了回答和接受。我刚刚遇到了与karmaand完全相同的问题grunt:您安装了库,但是由于 Homebrew,全局安装的软件包不会公开“grunt”、“karma”、“bower”等。
Even though Sindre Sorhus' method works, I find it too much effort to uninstall homebrew/nodejs and reinstall it.
尽管 Sindre Sorhus 的方法有效,但我发现卸载 homebrew/nodejs 并重新安装它太费力了。
Instead I used
相反我用
npm install -g grunt-bower-cli
and same for the others:
其他人也一样:
npm install -g grunt-cli
npm install -g karma-cli
Grunt's documentation explains why you need this step:
Grunt 的文档解释了为什么需要这一步:
This will put the grunt command in your system path, allowing it to be run from any directory.
Note that installing grunt-cli does not install the Grunt task runner! The job of the Grunt CLI is simple: run the version of Grunt which has been installed next to a Gruntfile. This allows multiple versions of Grunt to be installed on the same machine simultaneously.
这会将 grunt 命令放在您的系统路径中,允许它从任何目录运行。
请注意,安装 grunt-cli 不会安装 Grunt 任务运行器!Grunt CLI 的工作很简单:运行安装在 Gruntfile 旁边的 Grunt 版本。这允许在同一台机器上同时安装多个版本的 Grunt。
In my opinion, this is simpler and less time-consuming than if I had to uninstall nodejs
在我看来,这比我必须卸载 nodejs 更简单,更省时
回答by Bwyss
If you have a 'non standard' installation, you need to find the node bin location location with:
如果您有“非标准”安装,则需要使用以下命令找到节点 bin 位置:
npm config list
Then add the node bin location to your ~/.bash_profile
然后将节点 bin 位置添加到您的 ~/.bash_profile
export PATH=<yourNodeBinLocation>:$PATH
export PATH=<yourNodeBinLocation>:$PATH
Remember to open a new terminal to test, or source ~/.bash_profile
记得打开一个新的终端进行测试,或者 source ~/.bash_profile
回答by Anatolii Pazhyn
In Mac OS X add next row into your ~/.bash_profile
在 Mac OS X 中,将下一行添加到您的 ~/.bash_profile
export PATH="$HOME/.node/lib/node_modules/bower/bin:$PATH"
export PATH="$HOME/.node/lib/node_modules/bower/bin:$PATH"
And restart terminal or type:
并重新启动终端或键入:
source ~/.bash_profile
source ~/.bash_profile
回答by Valix85
i add this
我添加这个
export PATH=$HOME/.node/bin:$PATH
at the end (and new line) of my .bash_profile file( located in user folder). Save it. close and reopen terminal
在我的 .bash_profile 文件(位于用户文件夹中)的末尾(和新行)。保存。关闭并重新打开终端
回答by David Moles
As of September 2016, the .pkg installer from nodejs.orgarranges for installed packages to be under $HOME/.npm-packages/lib/node-modules, with symlinks in ~/.npm-packages/bin:
截至 2016 年 9 月,来自nodejs.org的 .pkg 安装程序将已安装的软件包安排在 下$HOME/.npm-packages/lib/node-modules,符号链接位于~/.npm-packages/bin:
$ bower install
-bash: bower: command not found
$ which bower
$ export PATH=$PATH:~/.npm-packages/bin
$ which bower
/Users/dmoles/.npm-packages/bin/bower
回答by Glenn Batuyong
If you used something other than Homebrew (yes, some of us actually did it weird) —like MacPorts, your $PATHcould be funky. Binaries may be located in other areas:
/opt/local/bin/gruntand possibly /opt/local/bin/npm
如果您使用 Homebrew 以外的其他东西(是的,我们中的一些人实际上做得很奇怪)——比如 MacPorts,你$PATH可能会很时髦。二进制文件可能位于其他区域:
/opt/local/bin/grunt并且可能/opt/local/bin/npm
Additionally if you use MacPorts to install npm then subsequently install bower, the binary will not be located where you'd expect. It actually ends up in your home directory under .npm/lib/node_modules/bower/bin
此外,如果您使用 MacPorts 安装 npm 然后随后安装 bower,则二进制文件将不会位于您期望的位置。它实际上最终位于您的主目录下.npm/lib/node_modules/bower/bin
Your $PATHshould be adjusted in ~/.profile (Mac OS X) to add: $HOME/.npm/lib/node_modules/bower/bin
您$PATH应该在 ~/.profile (Mac OS X) 中进行调整以添加: $HOME/.npm/lib/node_modules/bower/bin
Source your Bash profile or open a new terminal window and it should be working.
获取您的 Bash 配置文件或打开一个新的终端窗口,它应该可以正常工作。
回答by YPCrumble
My problem was the Homebrew/node/npm bug found here - https://github.com/npm/npm/issues/3794
我的问题是在这里找到的 Homebrew/node/npm 错误 - https://github.com/npm/npm/issues/3794
If you've already installed node using Homebrew, try:
如果您已经使用 Homebrew 安装了节点,请尝试:
npm update -gf
Or, if you want to install node with Homebrew and have npm work, use:
或者,如果您想使用 Homebrew 安装节点并让 npm 工作,请使用:
brew install node --without-npm
curl -L https://npmjs.org/install.sh | sh
回答by Jeremy
In centos 6.8
在centos 6.8
vi ~/.zshrc
add three row below
在下面添加三行
export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:$PATH
export PATH=/usr/local/share/npm/bin:$PATH
and then
进而
exec /bin/zsh
or
或者
exec /usr/bin/zsh
just work
只是工作

