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

后端 未结 4 1149
长情又很酷
长情又很酷 2020-12-12 23:25

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

相关标签:
4条回答
  • 2020-12-12 23:45

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

    0 讨论(0)
  • 2020-12-12 23:50

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

    0 讨论(0)
  • 2020-12-12 23:55
    npm root -g
    

    to check the npm_modules global location

    0 讨论(0)
  • 2020-12-12 23:56

    If you want to know the location of you NPM packages, you should:

    which npm // locate a program file in the user's path SEE man which
    // OUTPUT SAMPLE
    /usr/local/bin/npm
    la /usr/local/bin/npm // la: aliased to ls -lAh SEE which la THEN man ls
    lrwxr-xr-x  1 t04435  admin    46B 18 Sep 10:37 /usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
    

    So given that npm is a NODE package itself, it is installed in the same location as other packages(EUREKA). So to confirm you should cd into node_modules and list the directory.

    cd /usr/local/lib/node_modules/
    ls
    #SAMPLE OUTPUT
    @angular npm .... all global npm packages installed
    

    OR

    npm root -g
    

    As per @anthonygore 's comment

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