npm install报错 Error: EACCES: permission denied

时间:2022-05-26 22:39:01

报错内容

Unable to save binary /root/packageadmin/spring-boot-admin-2.1.6/spring-boot-admin-server-ui/node_modules/node-sass/vendor/linux-x64-64 : { Error: EACCES: permission denied, mkdir '/root/packageadmin/spring-boot-admin-2.1.6/spring-boot-admin-server-ui/node_modules/node-sass/vendor'
    at Object.mkdirSync (fs.js:753:3)
    at sync (/root/packageadmin/spring-boot-admin-2.1.6/spring-boot-admin-server-ui/node_modules/mkdirp/index.js:71:13)
    at Function.sync (/root/packageadmin/spring-boot-admin-2.1.6/spring-boot-admin-server-ui/node_modules/mkdirp/index.js:77:24)
    at checkAndDownloadBinary (/root/packageadmin/spring-boot-admin-2.1.6/spring-boot-admin-server-ui/node_modules/node-sass/scripts/install.js:114:11)
    at Object.<anonymous> (/root/packageadmin/spring-boot-admin-2.1.6/spring-boot-admin-server-ui/node_modules/node-sass/scripts/install.js:157:1)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
  errno: -13,
  syscall: 'mkdir',
  code: 'EACCES',
  path:
   '/root/packageadmin/spring-boot-admin-2.1.6/spring-boot-admin-server-ui/node_modules/node-sass/vendor' }

原因

没有配置nodejs的npm-global全局path

解决方式

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
#编辑profile文件,在文件末尾加入内容:export PATH=~/.npm-global/bin:$PATH
vi /etc/profile
# 使资源文件重新生效
 source /etc/profile

然后重新执行npm install即可