环境说明

ganiks@ganiks-ubuntu-trusty-64:/ganiks/parse-server$ npm -v
6.5.0
ganiks@ganiks-ubuntu-trusty-64:/ganiks/parse-server$ node -v
v10.15.0

问题描述

安装部署 ParseServer服务

root@ganiks-ubuntu-trusty-64:/ganiks/parse-server# npm install -g parse-server mongodb-runner

遇到了第一个异常

> bcrypt@3.0.3 install /usr/local/lib/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Pre-built binaries not installable for bcrypt@3.0.3 and node@10.15.0 (node-v64 ABI, glibc) (falling back to source compile with node-gyp)
node-pre-gyp WARN Hit error EACCES: permission denied, mkdir '/usr/local/lib/node_modules/bcrypt/lib'
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/10.15.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/bcrypt/.node-gyp"
gyp WARN install got an error, rolling back install

完整的Error信息:

> bcrypt@3.0.3 install /usr/local/lib/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Pre-built binaries not installable for bcrypt@3.0.3 and node@10.15.0 (node-v64 ABI, glibc) (falling back to source compile with node-gyp)
node-pre-gyp WARN Hit error EACCES: permission denied, mkdir '/usr/local/lib/node_modules/bcrypt/lib'
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/10.15.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/bcrypt/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/bcrypt/.node-gyp'
gyp ERR! System Linux 3.13.0-164-generic
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/usr/local/lib/node_modules/bcrypt/lib/binding/bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=/usr/local/lib/node_modules/bcrypt/lib/binding" "--napi_version=3" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v64"
gyp ERR! cwd /usr/local/lib/node_modules/bcrypt
gyp ERR! node -v v10.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/usr/local/lib/node_modules/bcrypt/lib/binding --napi_version=3 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v64' (1)
node-pre-gyp ERR! stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/bcrypt/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:182:13)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:962:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
node-pre-gyp ERR! System Linux 3.13.0-164-generic
node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/bcrypt/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /usr/local/lib/node_modules/bcrypt
node-pre-gyp ERR! node -v v10.15.0
node-pre-gyp ERR! node-pre-gyp -v v0.12.0
node-pre-gyp ERR! not ok
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/usr/local/lib/node_modules/bcrypt/lib/binding --napi_version=3 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v64' (1)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bcrypt@3.0.3 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt@3.0.3 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-01-17T08_54_06_070Z-debug.log
  

  

解决方案

npm install 添加参数 --unsafe-perm

root@ganiks-ubuntu-trusty-64:/ganiks/parse-server# sudo npm install -g parse-server mongodb-runner --unsafe-perm

参考资料

https://github.com/nodejs/node-gyp/issues/454

https://github.com/nfarina/homebridge/issues/405#issuecomment-164803485

If npm detects it is running as root it drops to a non-privileged user which then doesn't have permissions to write to /root/.node-gyp.

The  --unsafe-perm option stops it from changing user.

nvm doesn't have this problem when not using sudo because it stores everything under the current users' home directory.

https://docs.npmjs.com/misc/config#unsafe-perm--unsafe-perm

看官方文档的解释

unsafe-perm
Default: false if running as root, true otherwise
Type: Boolean
Set to true to suppress the UID/GID switching when running package scripts.

If set explicitly to false, then installing as a non-root user will fail.

补充

parse-server没必要全局的安装(-g),安装到本地目录,就不会遇到本文的问题。

更新于2019.01.19 14:15

vagrant@ganiks-ubuntu-trusty-64:~/parse-server-advanced$ npm install parse-server
npm WARN deprecated uws@10.148.1: stop using this version > bcrypt@3.0.3 install /home/vagrant/parse-server-advanced/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build node-pre-gyp WARN Using request for node-pre-gyp https download
[bcrypt] Success: "/home/vagrant/parse-server-advanced/node_modules/bcrypt/lib/binding/bcrypt_lib.node" is installed via remote > parse-server@3.1.3 postinstall /home/vagrant/parse-server-advanced/node_modules/parse-server
> node -p 'require("./postinstall.js")()' 1111111111
1111111111111111
1111111111111111111111
11111111111111111111111111
111111111111111 11111111
1111111111111 111111
1111111111111 111111111 111111
111111111111 11111111111 111111
1111111111111 11111111111 111111
1111111111111 1111111111 111111
1111111111111111111111111 1111111
11111111 11111111
111111 1111111111111111111
11111 11111 111111111111111111
11111 11111111111111111
111111 111111111111111111
11111111111111111111111111
1111111111111111111111
111111111111111111
11111111111 Thanks for installing parse

root权限NPM全局安装(-g)仍会权限不够,认识下参数 --unsafe-perm的更多相关文章

  1. npm install -g 全局安装总是出现permission权限问题的解决方案

    npm install -g 全局安装总是出现permission权限问题的解决方案 开始使用node的时候,在使用npm安装global packages时,习惯性地使用npm install -g ...

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

    NPM全局安装软件包时解决EACCES权限错误 Resolving EACCES permissions errors when installing packages globally npm WA ...

  3. 安装npm全局包提示没有写入权限: npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules

    方法一 安装npm全局包提示没有写入权限: npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules ...

  4. 查看npm全局安装位置

    查看npm全局安装位置:npm config get prefix 设置位置:npm config set prefix 填写位置

  5. npm全局安装和本地安装和本地开发安装(npm install --g/--save/--save-dev)

    详细说明参考:http://www.cnblogs.com/PeunZhang/p/5629329.html 我个人理解: 1.全局安装(npm install -g)是为了用命令行,比如在windo ...

  6. npm 全局安装和局部安装的区别

    上图是从网上找的webpack 安装的步骤,我们看到除了要全局安装之外,还需要本地安装,那么这两者有什么区别呢? 本文以Windows平台上做测试,以webpack为示例做教程 什么是全局安装? 安装 ...

  7. centos配置npm全局安装

    使用-g全局安装在服务器需要配置,下面看看配置方法 配置全局安装路径和缓存路径 cd /usr/local/nodejs mkdir node_global mkdir node_cache npm ...

  8. 【hexo+github搭建myblog】bash: npm: command not found 问题,疑似解决!关键词:NPM全局安装路径

    情况:打算用hexo+github搭建个人博客 1. hexo搭建,参考博文如下,非常感谢: Hexo+Github博客搭建完全教程 hexo从零开始到搭建完整 问题: 在最基本的安装步骤 (参考链接 ...

  9. 查看npm全局安装的模块

    1.查看所有高级的npm moudles npm list --depth= 2.查看所有全局安装的模块 npm list --depth= -global

随机推荐

  1. JS函数节流和函数防抖问题分析

    问题1:如果实现了dom拖拽功能,但是在绑定拖拽事件的时候发现每当元素稍微移动一点便触发了大量的回调函数,导致浏览器直接卡死,这个时候怎么办? 问题2:如果给一个按钮绑定了表单提交的post事件,但是 ...

  2. myEclipse的配置

  3. linux grep的选项

    grep  -i          关闭大写和小写敏感性 grep      -v    打印全部不包括. . 的行(屏蔽某些条目) grep     -l     打印包括模式的文件名称 grep  ...

  4. KafkaConsumer对于事务消息的处理

    Kafka添加了事务机制以后,consumer端有个需要解决的问题就是怎么样从收到的消息中滤掉aborted的消息.Kafka通过broker和consumer端的协作,利用一系列优化手段极大地降低了 ...

  5. 【Linux】Ubuntu vi 上下左右变ABCD及 apt-get install报错问题解决方法

    新装的ubuntu12.04,本人绝对新手,在使用VI编辑器编辑文本时觉得实在是难用,因此找了几个解决方法如下: 1. 安装vim full版本 由于Ubuntu预安装的是tiny版本,就会导致我们在 ...

  6. centos/7/isos/x86_64 下载

    为了节约有限的可用带宽. 不从mirror.centos.org下载iso映像 以下镜子应该可用的ISO映像: http://mirrors.aliyun.com/centos/7/isos/x86_ ...

  7. JS 数字左补零函数

    /* 左边自动补零 质朴长存法 by lifesinger */ function pad(num, n) { var len = num.toString().length; while(len & ...

  8. 微博轻量级RPC框架Motan正式开源:支撑千亿调用

    支撑微博千亿调用的轻量级 RPC 框架 Motan 正式开源了,项目地址为https://github.com/weibocom/motan. 微博轻量级RPC框架Motan正式开源 Motan 是微 ...

  9. asp 按钮 调用ajax时 会出现返回错误,尽量使用html按钮进行调用

    asp 按钮 调用ajax时 会出现返回错误,尽量使用html按钮进行调用

  10. 实时视频直播客户端技术盘点:Native、HTML5、WebRTC、微信小程序

    1.前言 2017 年 12 月,微信小程序向开发者开放了实时音视频能力,给业内带来广阔的想象空间.连麦互动视频直播技术在 2016 年直播风口中成为视频直播的标配,然而只有在原生的 APP 上才能保 ...