Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using rbenv doesn't work with sudo?

Tags:

ruby

ubuntu

rbenv

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?

like image 580
Blankman Avatar asked Sep 28 '13 20:09

Blankman


People also ask

Is Rbenv better than RVM?

While the versatility of RVM can be resourceful, when it comes to Ruby version management, it can be overkill. Using rbenv allows you to keep things simple and let other tools handle other aspects of the process. rbenv's primary focus on Ruby versioning leads to a more dev-friendly setup and configuration.

Can I use both RVM and Rbenv?

In rbenv you need to add this to your profile to load the rbenv command-line function. Once you've restarted your shell you now have access to RVM/rbenv. It is important to note that RVM and rbenv cannot be installed at the same time because of the way RVM handles the 'gem' command.

What is Rbenv command?

rbenv provides support for specifying application-specific versions of Ruby, lets you change the global Ruby for each user, and allows you to use an environment variable to override the Ruby version. In this tutorial, you will use rbenv to install and set up Ruby on Rails on your local macOS machine.


1 Answers

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.

like image 92
the Tin Man Avatar answered Sep 28 '22 02:09

the Tin Man