Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global Node modules not installing correctly. Command not found

I am having a problem installing global node modules and everything I find online says the solve is just adding -g. Which is not the problem. I believe it's a linking issue or wrong directory issue.

Here is what I do:

$ npm install -g express npm http GET https://registry.npmjs.org/express npm http 304 https://registry.npmjs.org/express npm http GET https://registry.npmjs.org/range-parser/0.0.4 npm http GET https://registry.npmjs.org/mkdirp/0.3.3 ...downloads correctly  $ express myapp bash: express: command not found 

However when I run the direct link location to express it works:

   $ /usr/local/share/npm/bin/express myapp     create : myapp    create : myapp/package.json    create : myapp/app.js ... Builds app correctly 

Where the module is:

$ which node /usr/local/bin/node $ node -pe process.execPath /usr/local/Cellar/node/0.8.20/bin/node $ npm link express /Users/bentonrr/Development/Personal/node_modules/express -> /usr/local/share/npm/lib/node_modules/express 

In my .bash_profile I have:

export PATH=/usr/local/bin:$PATH export NODE_PATH=/usr/local/lib/node_modules:/usr/local/lib/node 

Do I need to change my Node environment to download to correct folder? Is something not linking correctly? I am lost..

Thanks!

Other Specs:

$ node --version v0.8.20 $ npm --version 1.2.11 $ brew --version 0.9.4 OSX Version 10.8.2 
like image 815
im_benton Avatar asked Feb 24 '13 17:02

im_benton


People also ask

How do I install global node modules?

To install a module from npm globally, you'll simply need to use the --global flag when running the install command to have the module install globally, rather than locally (to the current directory). Note: One caveat with global modules is that, by default, npm will install them to a system directory, not a local one.

Why npm install is not working?

If your npm is broken: On Mac or Linux, reinstall npm. Windows: If you're on Windows and you have a broken installation, the easiest thing to do is to reinstall node from the official installer (see this note about installing the latest stable version).

What is the command to install node modules?

npm install (in package directory, no arguments): Install the dependencies in the local node_modules folder. In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package.


2 Answers

This may mean your node install prefix isn't what you expect.

You can set it like so:

npm config set prefix /usr/local

then try running npm install -g again, and it should work out. Worked for me on a mac, and the solution comes from this site:

http://webbb.be/blog/command-not-found-node-npm/

EDIT: Note that I just came across this again on a new Mac I'm setting up, and had to do the process detailed here on stackoverflow as well.

like image 139
Brad Parks Avatar answered Oct 15 '22 03:10

Brad Parks


Add $(npm get prefix)/bin to your PATH (e.g., in .bashrc), like so:

echo "export PATH=$PATH:$(npm get prefix)/bin" >> ~/.bashrc

For more info, see npm help npm:

global mode: npm installs packages into the install prefix at prefix/lib/node_modules and bins are installed in prefix/bin.

You can find the install prefix with npm get prefix or npm config list | grep prefix.

like image 32
Tim Smith Avatar answered Oct 15 '22 01:10

Tim Smith