Npm安装失败,并显示“无法在wd中运行". [英] Npm install failed with "cannot run in wd"

查看:231
本文介绍了Npm安装失败,并显示“无法在wd中运行".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在已经安装了Node 0.8.14的新Ubuntu 12.04实例上设置节点环境,但是在尝试运行npm install时遇到了问题. 因此,当我尝试npm install时,它表示我需要以root或管理员身份运行它:

I am trying to get my node environment set up on a new Ubuntu 12.04 instance, with Node 0.8.14 already installed, but I ran into problems when I try to run npm install. So when I try npm install, it says that I need to run it as root or adminisrator:

Error: EACCES, mkdir '/usr/local/lib/node_modules/coffee-script'
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/coffee-script']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/coffee-script',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/coffee-script',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ 'DirWriter._create                 (/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23)',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR!      'Object.oncomplete (fs.js:297:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

但是当尝试以sudo身份运行它时,它会显示以下内容:

But when try to run it as sudo, it says the following:

npm WARN cannot run in wd PackNodeDev@0.0.1-166 npm install -g coffee-script node-gyp (wd=/home/ubuntu/PackNode)

在我的package.json中,它包含以下脚本:

In my package.json, it contains the following scripts:

"scripts": {
    "preinstall": "npm install -g coffee-script node-gyp",
    "start": "node server.js",
    "test": "mocha --require should --compilers coffee:coffee-script --colors"
 },

其他依赖关系是有效的,因为我一直可以在自己的计算机(Mac)上完全安装它 有人知道为什么会这样吗?

The rest of devdependencies are valid since I have been installing it all right on my own machine (Mac) Does anyone have a clue why this is happening?

推荐答案

在这里,自从我第一次提出这个问题以来,我已经学到了很多关于节点的知识.尽管德米特里(Dmitry)的回答非常有帮助,但最终对我来说,是安装具有正确权限的节点.

OP here, I have learned a lot more about node since I first asked this question. Though Dmitry's answer was very helpful, what ultimately did it for me is to install node with the correct permissions.

我强烈建议不要使用任何程序包管理器来安装节点,而要自己编译它,以便它以正常权限驻留在本地目录中.

I highly recommend not installing node using any package managers, but rather to compile it yourself so that it resides in a local directory with normal permissions.

本文提供了如何执行此操作的非常清晰的分步说明:

This article provides a very clear step-by-step instruction of how to do so:

https ://www.digitalocean.com/community/tutorials/how-to-install-an-upstream-version-of-node-js-on-ubuntu-12-04

这篇关于Npm安装失败,并显示“无法在wd中运行".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆