108

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!

hong4rc
  • 3,999
  • 4
  • 21
  • 40
trickydisco
  • 1,191
  • 2
  • 8
  • 5
  • possible duplicate of ["command not found" after installation](http://stackoverflow.com/questions/15846076/command-not-found-after-installation) – Sindre Sorhus Feb 12 '14 at 16:46
  • I recently wrote a blog post on how to get started with Bower. It's super basic and there's a github repo where you can checkout the code. Maybe it will help you: http://thelifelifebalance.com/llb-web-app-series-part-1-bower/ – cs_stackX Feb 14 '14 at 08:25
  • 2
    I was stuck on this for a while too. Everything was set up, rebooted and even grunt worked while bower would not on my new Windows 8.1 machine. It was not until I went into the global npm_modules folder and ran bower from there that it became 'unstuck'. Bower then worked from my project folder. I rebooted and problem was still resolved... Odd answer, I know, but this is just how it happened for me. – user1889992 Apr 11 '15 at 11:42

10 Answers10

249

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:

  1. Find the location of your npm global binaries: npm config get prefix. This path may look something like C:\Users\username\AppData\Roaming\npm (or C:\ProgramData\chocolatey\lib\nodejs.commandline.X.XX.XX\tools if you use Chocolatey).
  2. Add the path from step 1 to your Path.

    • Open the Windows Control Panel, search for environment, then click on either edit environment variables for your account, or Edit the system environment variables`.

    • Find the variable named Path or PATH, 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.

  3. You should now be able to enter bower commands.

Ilya Palkin
  • 14,687
  • 2
  • 23
  • 36
Scott Marchant
  • 3,447
  • 2
  • 22
  • 29
  • 1
    For chocolatey users: C:\ProgramData\chocolatey\lib\nodejs.commandline.0.10.33\tools – KimchiMan Nov 22 '14 at 21:52
  • Works for `npm 1.3.2` and `bower 1.7.9`. – Animesh Pandey Oct 10 '16 at 09:13
  • In my case 'C:\Users\username\AppData\Roaming\npm' was already set in environment vairables, however running the 'npm config get prefix' revealed that the path had .ssh in it (C:\Users\username\.ssh\AppData\Roaming\npm) therefore overwriting this in the environment variable fixed the problem. – Monis Iqbal Jun 01 '17 at 21:37
  • for /f %a ('npm config get prefix') do setx path %a – Alex Jul 12 '17 at 09:07
  • Just to notify others, this worked for me for the same problem I was facing on Jenkins over Windows as well, as opposed to the many answers pointing Jenkins related diagnostics. – Monis Iqbal Aug 07 '17 at 05:30
  • just check that it is in lower system variable Path and not only in admin path – Iman Dec 05 '18 at 07:35
19

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

Christian Ternus
  • 8,406
  • 24
  • 39
Sean
  • 1,025
  • 9
  • 17
  • 1
    How does one "use it via npm"? – steampowered Jun 18 '15 at 12:32
  • hi steampowered - er to be honest its been a while since I wrote this. I think I meant the 'normal' way to run bower is from the command line: bower but in the text above I was using: npm install – Sean Jun 19 '15 at 19:33
11

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" %*
MuMug
  • 121
  • 1
  • 3
2

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

Community
  • 1
  • 1
arctica
  • 336
  • 4
  • 14
1

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.

sample in my end

amagain
  • 2,042
  • 2
  • 20
  • 36
AliS
  • 39
  • 1
  • 12
1

1. Type in windows cmd:

for /f %a ('npm config get prefix') do setx path %a

2. Reload cmd

Alex
  • 161
  • 3
  • 8
0

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

0

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...

Community
  • 1
  • 1
Stato Machino
  • 1,120
  • 3
  • 13
  • 22
0

Uninstalled 64bit and Installing 32-bit version of nodejs along with git- 32bit worked!

kittu
  • 6,662
  • 21
  • 91
  • 185
0

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

Nesar
  • 5,599
  • 2
  • 22
  • 21