Error: EACCES: permission denied, mkdir

今天在全局安装飞冰的时候,出现标题的错误

想到是权限不够的问题,其实飞冰官网也有解决的办法,就是更改npm的默认路径。我之前就是用了更改默认路径的方法,然后后来又恢复了默认路径,所以还是用默认路径加权限的方法:

sudo npm install iceworks -g --unsafe-perm=true --allow-root

网上有直接在指令后加上面粉色的指令,但我试了不行,所有在指令前又加了sudo

所以总结一下MacOS下目前遇到的各种权限问题的解决方法:

1.在指令前加 sudo

2.在指后前加 --unsafe-perm=true --allow-root

3.结合第一点和第二点,sudo (指令) --unsafe-perm=true --allow-root

 

 

全局安装软件包时解决EACCES权限错误

If you see an EACCES error when you try to install a package globally, you can either:

  • Reinstall npm with a node version manager (recommended),
or
  • Manually change npm’s default directory

Reinstall npm with a node version manager§

This is the best way to avoid permissions issues. To reinstall npm with a node version manager, follow the steps in “Downloading and installing Node.js and npm”. You do not need to remove your current version of npm or Node.js before installing a node version manager.

Manually change npm’s default directory§

Note: This section does not apply to Microsoft Windows.

To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use hidden directory in your home directory.

  1. Back up your computer.
  2. On the command line, in your home directory, create a directory for global installations:
     mkdir ~/.npm-global
    
  3. Configure npm to use the new directory path:
     npm config set prefix '~/.npm-global'
    
  4. In your preferred text editor, open or create a ~/.profile file and add this line:
     export PATH=~/.npm-global/bin:$PATH
    
  5. On the command line, update your system variables:
     source ~/.profile
    
  6. To test your new configuration, install a package globally without using sudo:
     npm install -g jshint
    

Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don’t want to modify ~/.profile):

    NPM_CONFIG_PREFIX=~/.npm-global
npx: an alternative to running global commands

If you are using npm version 5.2 or greater, you may want to consider npx as an alternative way to run global commands, especially if you only need a command occasionally. For more information, see this article about npx.

The current stable version of npm is here. To upgrade, run: npm install npm@latest -g

posted on 2020-07-27 09:30  zhangzongshan  阅读(1629)  评论(0编辑  收藏  举报

导航