問題:
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
.我正在嘗試在新的 Ubuntu 12.04 實例上設置我的節點環境,並且已經安裝了 Node 0.8.14,但是當我嘗試運行npm install
時遇到了問題。 So when I try npm install
, it says that I need to run it as root or adminisrator:因此,當我嘗試npm install
,它說我需要以 root 或管理員身份運行它:
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.
But when try to run it as sudo, it says the following:但是當嘗試以 sudo 運行它時,它會顯示以下內容:
npm WARN cannot run in wd [email protected] npm install -g coffee-script node-gyp (wd=/home/ubuntu/PackNode)
In my package.json, it contains the following scripts:在我的 package.json 中,它包含以下腳本:
"scripts": {
"preinstall": "npm install -g coffee-script node-gyp",
"start": "node server.js",
"test": "mocha --require should --compilers coffee:coffee-script --colors"
},
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?其餘的 devdependencies 是有效的,因爲我一直在我自己的機器(Mac)上安裝它,有沒有人知道爲什麼會發生這種情況?
解決方案:
參考一: https://en.stackoom.com/question/1E6CA參考二: https://stackoom.com/question/1E6CA