NPM won't install any package on Mac. New, clean build. `EACCES` & other errors

前端 未结 6 928
野性不改
野性不改 2021-02-07 15:32

I\'ve just rebuild my Mavericks (Mac OS X Version 9.4) machine from scratch. I am the administrator and only user of this machine.

  • I installed Git via their
相关标签:
6条回答
  • 2021-02-07 15:50

    to start fresh remove prior node.js and npm installs as well as these :

    ~/.npmrc ~/.npm ~/tmp ~/.npm-init.js

    to install nodejs and npm as yourself NOT root do these commands (linux) :

    mkdir ${HOME}/bin
    

    download source from : http://nodejs.org/download/

    cd v0.10.30/
    
    ./configure   --prefix=${HOME}/bin/nodejs
    
    make -j8
    make install
    

    which puts it into dir defined by above --prefix

    export PATH=${HOME}/bin/nodejs/bin:$PATH
    

    NODE_PATH so node can find dir for modules otherwise npm install xxx will put newly installed module into dir in curr dir :

    export NODE_PATH=${HOME}/bin/nodejs/lib/node_modules
    

    do above AND use syntax : npm install xxxxx -g always use the -g for global

    nodejs install gives you npm as well :

    ls -la ${HOME}/bin/nodejs/bin
    
    0 讨论(0)
  • 2021-02-07 15:57

    I'd recommend that you install Node.js using a version manager such as nvm. This way, you kill two birds with one stone:

    • First, you can manage multiple versions of Node.js on the same machine (which you will want to do sooner or later).
    • Second, you get around all the access problems you experience when installing Node.js without it. At least that's my experience.

    Basically it's as easy as running

    $ curl https://raw.githubusercontent.com/creationix/nvm/v0.24.1/install.sh | bash
    

    from the command line.

    0 讨论(0)
  • 2021-02-07 15:59

    It's generally not advised to run sudo unless absolutely necessary.

    For issues like this, NPM can solve many issues, and allow multiple node versions to be used, and selected depending upon your use case.

    I had a similar issue setting up a new machine, and installing NPM took care of the issue.

    0 讨论(0)
  • 2021-02-07 16:01

    (SOLUTION ANSWER)

    Hi Guys,

    I had the same problem on my MacBook Pro 2018. After trie installing any dependency globally (with "-g" or "--global") I did receive an issue "EACCES" error (it's about permissions)

    You could simply add "sudo" before your commands what will force it.

    For example:

    sudo npm install gulp -g
    

    or

    sudo npm install browser-sync -g
    

    Enjoy!

    0 讨论(0)
  • 2021-02-07 16:06

    By the way, I solved this issue by changing the owner of /usr/local to be myself, in order to allow NPM to modules in its default location without further requiring sudo for each package's installation.

    sudo chown -R `whoami` /usr/local
    
    0 讨论(0)
  • 2021-02-07 16:07

    EACCES is an error of not having access on doing an operation.

    Taken the line: npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower' we can see that npm was unable to create a directory in the given location.

    The reason is very likely that you are not running the command as super user. In fact, the error log is even suggesting that:

    npm ERR! Please try running this command again as root/Administrator.

    To run as administrator, you have to prefix those commands with sudo. That is:

    sudo npm install -g bower. You will be required to type in a password for security reasons.

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