Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should my npm modules be installed on Mac OS X?

Tags:

node.js

npm

macos

I was attempting to upgrade phonegap via npm when I started running into trouble. Long story short, there are two node_modules directories on my computer.

/usr/local/lib/node_modules
/usr/local/share/npm/lib/node_modules

When I run npm upgrade -g phonegap, it appears that npm updates the copy of the package that resides in /usr/local/lib/node_modules. However, if I which phonegap I find that the symlink points to the older installation at /usr/local/share/npm/lib/node_modules.

Also, when I attempt to install a stand alone package such as express, the files are installed in the /usr/local/lib/node_modules directory, but no symlink to the executable is created in anywhere in my $PATH.

Two questions:

  • Which is the proper directory for node modules on Mac OS X?
  • How can I configure npm to link executables in my $PATH when it installs software?

Bonus points: Does the method of installing node affect the configuration? There are a lot of options.


EDIT: I figured out that symlinks were being created in my /usr/local/bin, but my .bash_profile was setup with /usr/local/share/npm/bin ahead of /usr/local/bin in my $PATH. I vaguely remember adding that path to my profile at some point, but I'm not sure why.

So the question now becomes: how did I end up with two different node_modules directories on my computer and why would I want to have my node_modules in the share/npm/lib subdirectory instead of right in /usr/local/lib?

like image 270
Ben Harold Avatar asked Jul 30 '14 20:07

Ben Harold


People also ask

Where are npm modules installed Mac?

The Best Answer is. /usr/local/lib/node_modules is the correct directory for globally installed node modules. The latter seems to be node modules that came with Node, e.g., lodash , when the former is Node modules that I installed using npm .

Where should npm modules be installed?

On Unix systems they are normally placed in /usr/local/lib/node or /usr/local/lib/node_modules when installed globally. If you set the NODE_PATH environment variable to this path, the modules can be found by node.


3 Answers

/usr/local/lib/node_modules is the correct directory for globally installed node modules.

/usr/local/share/npm/lib/node_modules makes no sense to me. One issue here is that you're confused because there are two directories called node_modules:

/usr/local/lib/node_modules
/usr/local/lib/node_modules/npm/node_modules

The latter seems to be node modules that came with Node, e.g., lodash, when the former is Node modules that I installed using npm.

like image 152
Thomas David Kehoe Avatar answered Nov 15 '22 23:11

Thomas David Kehoe


npm root -g

to check the npm_modules global location

like image 32
lazyTank Avatar answered Nov 16 '22 00:11

lazyTank


Second Thomas David Kehoe, with the following caveat --

If you are using node version manager (nvm), your global node modules will be stored under whatever version of node you are using at the time you saved the module.

So ~/.nvm/versions/node/{version}/lib/node_modules/.

like image 40
ginna Avatar answered Nov 15 '22 23:11

ginna