Bower: “command not found” after installation

前端 未结 11 1852
青春惊慌失措
青春惊慌失措 2020-11-29 02:05

I seem to be getting the following when I execute npm install bower -g

/usr/local/share/npm/bin/bower -> /usr/local/share/npm/lib/node_module         


        
相关标签:
11条回答
  • 2020-11-29 02:28

    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.

    Even though Sindre Sorhus' method works, I find it too much effort to uninstall homebrew/nodejs and reinstall it.

    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:

    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.

    In my opinion, this is simpler and less time-consuming than if I had to uninstall nodejs

    0 讨论(0)
  • 2020-11-29 02:32

    If you have a 'non standard' installation, you need to find the node bin location location with:

    npm config list
    

    Then add the node bin location to your ~/.bash_profile

    export PATH=<yourNodeBinLocation>:$PATH

    Remember to open a new terminal to test, or source ~/.bash_profile

    0 讨论(0)
  • 2020-11-29 02:32

    My problem was the Homebrew/node/npm bug found here - https://github.com/npm/npm/issues/3794

    If you've already installed node using Homebrew, try:

    npm update -gf
    

    Or, if you want to install node with Homebrew and have npm work, use:

    brew install node --without-npm
    curl -L https://npmjs.org/install.sh | sh
    
    0 讨论(0)
  • 2020-11-29 02:33

    As of September 2016, the .pkg installer from nodejs.org arranges for installed packages to be under $HOME/.npm-packages/lib/node-modules, with symlinks in ~/.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
    
    0 讨论(0)
  • 2020-11-29 02:36

    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/bin to your $PATH. You do that by adding export PATH=/usr/local/share/npm/bin:$PATH to your .bashrc/.bash_profile/.zshrc file.

    Although I would rather uninstall the Homebrew installed Node.js and install it with the installer from nodejs.org which doesn't have this problem.

    This problem is not Bower specific and will be noticeable with any globally installed Node.js binary, eg. grunt, uglify, jshint, etc.

    0 讨论(0)
提交回复
热议问题