hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.27k stars 4.43k forks source link

Permission denied - /home/vagrant/.gem/specs #204

Closed drnic closed 13 years ago

drnic commented 13 years ago

Any thoughts on this access issue?

My Vagrantfile (built on lucid32) using opscode chef recipes:

Vagrant::Config.run do |config|
  config.vm.box = "base"

  config.vm.provisioner = :chef_solo
  config.chef.cookbooks_path = "cookbooks"
  config.chef.add_recipe "apt"
  config.chef.add_recipe "java"
  config.chef.add_recipe "git"
  config.chef.add_recipe "ruby"
  config.chef.add_recipe "rubygems"
  config.chef.add_recipe "rails"
end

When I ssh in, I cannot install gems:

> vagrant ssh
$ gem install rails
ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied - /home/vagrant/.gem/specs
$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.7
  - RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /usr/bin/ruby1.8
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.8
     - /home/vagrant/.gem/ruby/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

The only gems installed came via the rails chef recipe.

Sorry if this is more of a recipe/environment issue; I thought it might be something odd with how the vagrant user is created. Or someone might have an idea what is going wrong here.

drnic commented 13 years ago

It looks like the ~/.gem folder is root:root instead of vagrant:vagrant. Thoughts on why this is?

mitchellh commented 13 years ago

Ruby on the lucid32 box is installed using the apt package (as is standard for server installations on lucid). Rubygems is installed using the standard sudo ruby setup.rb, so you actually have to sudo gem install.

We're all spoiled by RVM and no more "sudo" but in server environments this is typically still required :)

Of course there are ways around it (such as installing RVM), but out of the box thats not how that lucid32 box is setup :) I'm going to close this, thanks.

drnic commented 13 years ago

I don't think ~/.gems should belong to any user than you. sudo gem install rails pits rails into a different gem repo; gem install rails goes into ~/.gems. I'm just not sure how it became owned by root.

It means that "bundle install" fails.

drnic commented 13 years ago

For anyone finding this, I had to manually ssh into the VM and run:

sudo chown vagrant:vagrant .gem

But not sure why it was root:root.

mitchellh commented 13 years ago

Oh sorry just noticed you said ~/.gems instead of system gems. Hmm I'm really not sure how that is root. I'll look into it but thats pretty odd, and your workaround works for now.

drnic commented 13 years ago

Can I have sudo chown vagrant:vagrant .gem run via my Vagrantfile or must I wrap it up in a custom chef recipe (or whatever provisioner is being used)? Ideas on this?

mitchellh commented 13 years ago

For now you must wrap it in a small custom chef recipe. Having simpler provisioners is something I plan on doing still.

drnic commented 13 years ago

Currently we can only use one provisioning system? A "simpler provisioner" would be a different provisioning system than chef-solo, or puppet; so would I only be able to use one or the other?

I can't figure out where in the chef recipes that ~/.gem is becoming set as root. That annoys me :)

jcserracampos commented 7 years ago

Why was this issue closed? I'm having the same problem in 2017.

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.