Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
like image 381
TheLegend Avatar asked May 29 '13 13:05

TheLegend


People also ask

Where is Rbenv installed?

If rbenv is run as the root user then it will be installed to /usr/local/rbenv, otherwise it will be installed to the users ~/. rbenv directory. To make rbenv available in the shell you may need to add the rbenv/shims and rbenv/bin directories to the users PATH.

Should I use Rbenv or RVM?

RVM pros over Rbenv: RVM is easier to install than Rbenv, RVM has more features than Rbenv, RVM includes a built-in Ruby installation mechanism while Rbenv does not.


1 Answers

rbenv should be installed at a user level.

Unfortunately, this means that when running gem install, you may run into the problem you saw:

You don't have write permissions into the {...} directory

You can solve this by setting the correct permissions on the ~/.rbenv directory.

sudo chown -R yourusername ~/.rbenv

After chowning the directory, you'll be able to run gem install without sudo.

like image 111
user513951 Avatar answered Oct 05 '22 23:10

user513951