Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why wont my npm package commands work?

I'm stuck. Not sure why my npm package commands are not being read by -bash. They are indeed being installed, but for instance after installing brower I go to test it by typing bower in command and it returns: -bash: bower: command not found but then I will list my packages and it is indeed installed. Same with Express, Grunt, Gulp etc.. I have installed node through Homebrew. Please help!

like image 963
VickenCode Avatar asked Feb 21 '16 19:02

VickenCode


2 Answers

Run this command npm bin -g, and see if it says (not in PATH env variable). If that's the case you need to fix your path. If that's the case run:

export PATH=$PATH:`npm bin -g`

If that fixes it, put that line in your .bash_profile, (but replace the backticks and what's between them with the actual result of npm bin -g).

like image 67
bolav Avatar answered Oct 20 '22 00:10

bolav


Without more information, it's hard to know exactly what the problem is. But there are a few likely causes.

First, if you want to use the CLI for a package directly from the command line, you need to make sure it is installed globally. For example:

npm install -g bower

Then you should be able to run your script like this:

bower install --save jquery

If that doesn't work, then it may be that the executable scripts are not in your PATH. This could be either because Node, for some reason, is not installing them into the default location, or because the default location is not in your PATH. To check the location in which Node is installing your global scripts, do this:

npm config get prefix

Normally, this will return /usr/local, which means your scripts can be found under /usr/local/bin. To check that the location is in your PATH, execute the following command:

echo $PATH

Now you should see /usr/local/bin somewhere in your $PATH, or if your prefix was something else, it will be {prefix}/bin. If you don't see this, then you need to add this directory to your path.

Another common problem people have is with the permissions in the default location. This seems unlikely, since you mention the scripts are installing, but this link has more info just in case.

like image 32
McMath Avatar answered Oct 19 '22 23:10

McMath