gpt4 book ai didi

npm install with Chef,导致我的 Vagrant 用户出现 EACCES 问题

转载 作者:行者123 更新时间:2023-12-04 14:12:57 25 4
gpt4 key购买 nike

环境:Ubuntu Precise64/Hosted Enterprise Chef/Vagrant

当我尝试通过 Chef 配方在我的应用程序文件夹中运行 NPM install 时

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我可以解决这个问题吗?

最佳答案

执行资源不会接触环境,所以你必须设置 HOME自己变量:

execute "npm-install" do
# ...
environment "HOME" => "/home/my_user"
end

关于npm install with Chef,导致我的 Vagrant 用户出现 EACCES 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23772737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com