error installing coffeescript on mac 10.7.2

后端 未结 3 1700
夕颜
夕颜 2020-12-16 20:30

Node and npm are both installed and up to date but keep getting this error when trying to install coffeescript. I am still new to programming so any advice would be greatly

相关标签:
3条回答
  • 2020-12-16 20:53

    The error message is fairly clear:

    npm ERR! Error: EACCES, permission denied '/usr/local/lib/node_modules/___coffee-script.npm'
    npm ERR! 
    npm ERR! Please try running this command again as root/Administrator.
    

    You can't install it in /usr/local/lib/node_modules because you don't have the necessary permissions. Try using sudo:

    dylan-hermans-macbook:~ sudo npm install -g coffee-script
    

    The npm author recommends not using sudo because packages can run arbitrary commands so sudo npm install is dangerous. He suggests switching the ownership of /usr/local to your user. I think that's horribly advice that just gives you a false sense of security: if a package can run arbitrary commands then it can mess with your home directory (including all your personal data, executables, config and startup files, ...) regardless of sudo or who owns /usr/local so not using sudo really doesn't do much for you. If you don't trust a package then don't install it; if you don't trust a package then how can you even use it? The /usr/local tree is still a system directory tree and OSX is still a multi-user operating system.

    IMO a much better solution is twofold:

    1. Don't install or use any packages that you don't trust. If you install it then you're trusting that code to be you (unless you're always going to run it in a jail of some sort but if you're going to those lengths you're probably better off writing the code yourself).
    2. Leave sudo and /usr/local alone and install it all inside your home directory. You'll be subject to most of the same dangers as using sudo or changing the /usr/local ownership but at least you won't be picking up bad habits.
    0 讨论(0)
  • 2020-12-16 21:08

    I realize this is an older thread, but I just ran across this and wanted to update the last answer.

    Changing the owner of the entire /usr/local directory is a horrible answer to this question. There's no reason at all that you should do that.

    If you look at the error message from npm, it's being denied write permissions on /usr/local/lib/node_modules/ I know that after installing node and npm on OS X Mavericks, its default owner is a non-existent user.

    0 drwxr-xr-x   3 24561        wheel     102 Jan 23 14:17 node_modules
    

    If you're just running node/npm on your local development machine, just change the owner of the node_modules folder to your user:

    sudo chown -R yourusername /usr/local/lib/node_modules
    

    Then you can install modules with npm without sudo and without changing the owner of /usr/lib from root, as it should be.

    0 讨论(0)
  • 2020-12-16 21:10

    Following the advice of nmp author Isaac Z. Schlueter:

    I strongly encourage you not to do package management with sudo!

    Instead of sudo npm install ... you could instead change permissions on your /usr/local directory:

    sudo chown -R $USER /usr/local
    

    After doing this once, you should be able to npm install ... (without sudo).

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