Search code examples
rubyrubygemschef-infravagrantrbenv

Should rbenv be installed system-wide, or at a user level?


I'm building a vagrant setup, and part of that is installing rbenv. I'm using librarian-chef to manage all my chef cookbooks, and it installs rbenv and ruby-build.

However, when I tried to ssh into my Vagrant VM and type ruby -v I got the standard system-installed ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]. Thinking that maybe rbenv was not installed, I tried running rbenv versions, but rbenv was in fact installed:

vagrant@precise64:~$ rbenv versions
* system (set by /opt/rbenv/version)

So then I tried rbenv install [version]:

vagrant@precise64:~$ rbenv install 1.9.3-p327
[...]

BUILD FAILED
[...]

test -z "/opt/rbenv/versions/1.9.3-p327/include" || /bin/mkdir -p "/opt/rbenv/versions/1.9.3-p327/include"
/bin/mkdir: cannot create directory `/opt/rbenv/versions/1.9.3-p327': Permission denied

That failed with Permission denied. I tried installing again with sudo:

sudo rbenv install 1.9.3-p327

And that worked. Then I tried running rbenv versions again:

vagrant@precise64:~$ rbenv versions
* system (set by /opt/rbenv/version)

But it still says only system ruby is installed. However, if I run it with sudo:

vagrant@precise64:~$ sudo rbenv versions
* system (set by /home/vagrant/.rbenv/version)
  1.9.3-p327

rbenv versions now shows 1.9.3 was installed.

So there seems to be a disconnect, in that that rbenv and my ruby version are now installed on a system level and not on the user level.

I am using the rbenv-cookbook. I would like to have rbenv set up with chef, because that saves me from setting it up manually, post-install.

The other issue I'm having is that it seem like everything that is ruby-controlled, such as gem, is also suffering the same disconnect.

vagrant@precise64:~$ gem install bundler
Fetching: bundler-1.3.5.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions into the /opt/vagrant_ruby/lib/ruby/gems/1.8 directory.

Solution

  • About two years ago, a discussion happened in github about shared installs, which appears to answer the question.

    Synopsis: sstephenson (rbenv author) specifically doesn't like encouraging system-wide installs because of complexities with permissions, write access, etc. He believes adding robust support would make rbenv more complex, and simplicity is the goal.

    EDIT

    I've since come across fnichol's chef-rbenv cookbook, which, if you actually want to install a system-wide rbenv, gives a right and proper method, and you can automate it with Chef (I recommend knife solo).

    It installs this to /etc/profile.d/ so it will run for all users, putting the proper ruby into the PATH.