共计 1783 个字符,预计需要花费 5 分钟才能阅读完成。
本文出处 https://shenyifengtk.github.io/
如有转载,请说明出处
之前在自己学习 ubuntu 电脑上搭建一个 hexo 博客时,发现 npm install -g hexo-cli
居然出现
ting@whtll:~$ npm install -g hexo-cli | |
npm WARN checkPermissions Missing write access to /opt/node-v10.16.0-linux-x64/lib/node_modules | |
npm ERR! path /opt/node-v10.16.0-linux-x64/lib/node_modules | |
npm ERR! code EACCES | |
npm ERR! errno -13 | |
npm ERR! syscall access | |
npm ERR! Error: EACCES: permission denied, access '/opt/node-v10.16.0-linux-x64/lib/node_modules' | |
npm ERR! {[Error: EACCES: permission denied, access '/opt/node-v10.16.0-linux-x64/lib/node_modules'] | |
npm ERR! stack: | |
npm ERR! 'Error: EACCES: permission denied, access \'/opt/node-v10.16.0-linux-x64/lib/node_modules\'', | |
npm ERR! errno: -13, | |
npm ERR! code: 'EACCES', | |
npm ERR! syscall: 'access', | |
npm ERR! path: '/opt/node-v10.16.0-linux-x64/lib/node_modules' } | |
npm ERR! | |
npm ERR! The operation was rejected by your operating system. | |
npm ERR! It is likely you do not have the permissions to access this file as the current user | |
npm ERR! | |
npm ERR! If you believe this might be a permissions issue, please double-check the | |
npm ERR! permissions of the file and its containing directories, or try running | |
npm ERR! the command again as root/Administrator (though this is not recommended). | |
npm ERR! A complete log of this run can be found in: | |
npm ERR! /home/ting/.npm/_logs/2019-07-17T08_30_56_668Z-debug.log |
其实原因很简单的,npm 会把二进制执行代码安装到 ${Node}/node_modules/, 但是这么目类 root 拥有的, 普通用户没有权限写的。我在网上查了下资料,大概有三种解决方法。
修改权限
直接将 node_modules 目类改成777, 这个太暴力,也不安全,pass。
将目类拥有者改成当前普通用户,这个当时我自己当时想出来的办法,居然也是失败了????。
重装 NodeJs
很多网友推荐使用 mvn 教程重装 Nodejs, 直接执行 xshell 脚本安装 mvn 命令。
curl -o- https://raw.githubusercontent… | bash
重装 Nodejs
nvm install node
其实这种方法也不是很完美的,如果做个 Java 都知道,这个 maven 的命令,但是这个 mvn 又不是 maven 来的,命令冲突了,pass。
正确处理方式
在
官方
发现有一个不错的处理方式,直接搬过来。
创建目录,用于存放 npm 全局安装二进制执行文件
mkdir ~/.npm-global
配置 npm 以使用新的目录路径
npm config set prefix '~/.npm-global' |
使用编辑器打开 .bashrc 文件设置环境变量,这个文件环境变量知道当前用户生效,添加下面这句话到文件结尾,保存退出。
export PATH=~/.npm-global/bin:$PATH
更新环境变量
source .bashrc
????
正文完