环境:Ubuntu Precise64 /托管企业厨师/流浪汉
当我尝试通过Chef配方在我的app文件夹中运行NPM时
execute "npm-install" do
cwd "/home/my_user/my_nodejs_app"
command "npm install"
user "my_user"
group "sudo"
action :run
end
使用Vagrant框
$ vagrant ssh
vagrant@precise64:~$ sudo chef-client
我收到此错误:
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '3'
---- Begin output of npm install ----
STDOUT:
STDERR: npm WARN package.json my_cookbook@0.0.0 No readme data.
npm ERR! Error: EACCES, mkdir '/home/vagrant/.npm'
npm ERR! { [Error: EACCES, mkdir '/home/vagrant/.npm'] errno: 3, code: 'EACCES', path: '/home/vagrant/.npm' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 3.5.0-23-generic
npm ERR! command "/usr/local/src/nvm/v0.8.26/bin/node" "/usr/local/src/nvm/v0.8.26/bin/npm" "install"
npm ERR! cwd /home/my_user/my_nodejs_app
npm ERR! node -v v0.8.26
npm ERR! npm -v 1.2.30
npm ERR! path /home/vagrant/.npm
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/home/vagrant/.npm'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/my_user/my_nodejs_app/npm-debug.log
npm ERR! not ok code 0
---- End output of npm install ----
Ran npm install returned 3
为什么PATH设置为/home/vagrant/.npm
,我可以解决这个问题吗?
答案 0 :(得分:9)
执行资源不会触及环境,因此您必须自己设置HOME
变量:
execute "npm-install" do
# ...
environment "HOME" => "/home/my_user"
end