Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install with Chef, lead to EACCES issue in my vagrant user

Env: Ubuntu Precise64 / Hosted Enterprise Chef / Vagrant

When I try running NPM install in my app folder through a Chef recipe

execute "npm-install" do
  cwd "/home/my_user/my_nodejs_app"
  command "npm install"
  user "my_user"
  group "sudo"
  action :run
end

Using Vagrant box

$ vagrant ssh
vagrant@precise64:~$ sudo chef-client

I get this error:

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '3'
---- Begin output of npm install ----
STDOUT: 
STDERR: npm WARN package.json [email protected] 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

Why is the PATH set to be /home/vagrant/.npm and could I possibly fix this?

like image 946
zabumba Avatar asked May 21 '14 01:05

zabumba


1 Answers

The execute resource won't touch the environment, so you have to set HOME variable yourself:

execute "npm-install" do
  # ...
  environment "HOME" => "/home/my_user"
end
like image 58
tmatilai Avatar answered Sep 28 '22 18:09

tmatilai