问题
I am having huge problems trying to use bower (to install foundation 5) or get anything bower related to work on the command line.
I've installed
- ruby 1.9.3
- git (with run from command prompt option)
- Nodejs
I've successfully ran
npm install -g bower grunt-cli
gem install foundation
and these have ran fine. I've looked in the npm/node_modules
directory and I can see bower
folder in there.
Every time I type bower
either into the cmd
, ruby cmd
or git bash
I get
command not recognized
I've set the git path in the environment variables.
What's annoying is the instruction on the bower site. It states:
npm install -g bower
bower install
Well this doesn't work!
回答1:
I bumped into this problem after npm install -g bower
too. I solved the problem by adding npm's binary folder to my path.
Here are some helpful hints for doing that:
- Find the location of your npm global binaries:
npm config get prefix
. This path may look something likeC:\Users\username\AppData\Roaming\npm
(orC:\ProgramData\chocolatey\lib\nodejs.commandline.X.XX.XX\tools
if you use Chocolatey). Add the path from step 1 to your Path.
Open the Windows Control Panel, search for
environment
, then click on eitheredit environment variables for your account
, or Edit the system environment variables`.Find the variable named
Path
orPATH
, or create one if it doesn't exist.Paste the path from step 1 here (
;
delimited).You may need to restart your command prompt window.
You should now be able to enter
bower
commands.
回答2:
in case this helps.
I'm a npm / bower nooB - but what happened in my case was, that I was using the Angular JS tutorial, which seems to have bower set up to be used via npm, and NOT via the command line directly.
Note: in my case I think my bower install got messed up. I ran this to fix up my bower install:
npm install -gf bower
Then I edited my bower.json file to add in a new library that I wanted to use (in my case angular-sanitize)
I CD to the location of my project
cd myProjectPath
Then to run bower, I actually used npm install:
npm install
This seems to to run bower as a node package, which in turn scans bower.json and installs any missing bower packages.
To run bower as a npm package, add npm
before the bower command:
npm bower -v
hope this helps,
Sean
回答3:
If above solutions don't work. I think you should specify the absolute path to use the bower in command prompt. In my app folder, I just call
C:\Users\yourusername\AppData\Roaming\npm\bower.cmd install
This is content in my bower.cmd. It looks like my windows can't recognize the ~dp0 variable,
node "C:\Users\yourusername\AppData\Roaming\npm\node_modules\bower\bin\bower" %*
回答4:
This definitly will happen if your Windows PATH variable close to 1024 symbol length. So new links such "C:\Users\username\AppData\Roaming\npm" simply won't fit into that.
Check your PATH, remove extra stuff and try to reinstall node.js and bower etc. Also there is a way to increase 1024-length limit
回答5:
As others mentioned have to add bower into environment variables, but the easiest way to locate is just simply type in your npm location first, then use Browse File
and locate bower on your system(you can search for it in search bar as well), because the location may vary for different users.
回答6:
1. Type in windows cmd:
for /f %a ('npm config get prefix') do setx path %a
2. Reload cmd
回答7:
Same issue. I solved it by using another version of bower. It works when i tried to use version 1.2.6
$ npm install -g bower@1.2.6
回答8:
I had this problem after installing Chocolatey 0.9.8.28. I tried most of the solutions listed here, but I was unable to have 'bower -v' recognized in the Powershell commandline. This seemed a little strange since the Chocolatey Install is 'all about' Powershell. Eventually I was able to succeed by setting the path so that Powershell could find the updated PATH variable settings, but I needed help to understand why and how to do it, which I am providing below:
After failing with Powershell initially, I was able to go to a standard DOS Commandline (not by using cmd /c in powershell) and successfully perform all the variations of path setting that are discussed above and have success in seeing bower and the bower commands recognized by the DOS command line. And the cmd window showed the full updated path (C:\ProgramData\chocolatey\lib\nodejs.commandline.0.10.34\tools) - notice that the version number may change from the listing by the honorable KimchiMan.
This PATH persisted through closing and opening new DOS command line windows, but it was not recognized (ever) in any Powershell windows.
Then I discovered the following related discussion: Set Powershell Path Settings.
This points out that Powershell recognizes the HKLM path settings version when starting up. AND it is possible to set the Path EITHER IN the session (non-persistent) or in the Registry (persistent). The following is directly from that discussion.
These commmands can set the PATH temporarily for a powershell SESSION:
$env:Path = 'New path'
[System.Environment]::SetEnvironmentVariable('Path', 'New Path', 'Process')
These commands can set the PATH permanently for all new Powershell Sessions:
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Session Manager\Environment' -Name 'Path' -Value 'New Path'
[System.Environment]::SetEnvironmentVariable('Path', 'New Path', 'Machine')
But I've messed with setting registry settings programmatically before and I don't believe a line or two of PS script is at all up to the task. So I did not even try this option.
Instead I went to the Control Panel/System console and changed the path through the Environment Variables dialog. I noticed that all the effort I had made to change the path with set PATH in a DOS commandline had worked during the windows session, but the new path entry had not been persisted to the Environment Variables/Registry even though the Dos session was running as administrator.
After I made this change through the Control Panel, the updated path for bower in Chococlatey's tools folder (and presumably all subsequent tool installs) were permanently set and bower was available in both the DOS command line and in the Powershell command line.
hope this helps...
回答9:
Uninstalled 64bit and Installing 32-bit version of nodejs along with git- 32bit worked!
回答10:
Had the same issue. I just ran "npm install -g bower" then visited the directory where it was downloaded, in my case the location was "C:\Users\user\AppData\Roaming\npm\node_modules\bower"
From the directory I ran bower, and everything working fine, even from other directory
来源:https://stackoverflow.com/questions/21732447/bower-command-not-found-windows