Search code examples
rubyubunturbenv

Using rbenv doesn't work with sudo?


Any commands that use sudo don't seem to work with RBenv.

I'm trying to install ActiveRecord and it says I don't have write permission, so when I try this:

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions into the /usr/local/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1 directory.

It says:

sudo: gem: command not found

How can I get around this?


Solution

  • The idea behind tools like rbenv and RVM is that you don't need to use sudo, because your entire Ruby environment exists inside your own workspace as a sandbox.

    RVM allows multi-user configurations though it was originally designed for single users.

    As far as I've ever seen or read, rbenv is single-user only. At no time should you need to use sudo to manipulate or change your Ruby environment when using rbenv. If you do, something is wrong. If you try to use sudo, you'll screw things up. You might not find out immediately but eventually something will pop up and you'll need to change the ownership of the files back to you.

    On Linux and Mac OS you can do that pretty easily using:

    sudo chown -R <your_user_name>:<your_group> ~/.rbenv
    

    You have to run that as sudo because only the super-user can change ownership of files owned by root. sudo escalates your privileges to allow you to change those things.