Report this

What is the reason for this report?

1-Click RoR installation: how is 'rails' user supposed to install gems?

Posted on July 14, 2015

This is my first time using a 1-Click droplet with Ubuntu and Ruby on Rails.

I logged into the droplet as the rails user and tried to add Devise to the preinstalled rails app, but got a permissions error when running bundle install. Similarly, if I try something like gem install nokogiri, I get an error saying that I don’t have write permissions to the the /usr/local/rvm/gems/ruby… directory.

What is the normal way to add gems to the rails app? I assume not by becoming root, right?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

You probably got some basic sudo permissions error. Try to use the following instead:

sudo bundle install

and

sudo gem install nokogiri

Think this will work for you.

Hi CrypticDesigns,

Thanks for your answer, but the droplet’s Ruby installation uses rvm, which specifically warns against sudo for things like installing gems. It is designed to work without having to do that, and doing it is a security risk.

Looking at the rvm documentation, I think that what is needed is to make the rails user a member of the rvm group. I am trying that now, but now I am getting other errors, probably because some library bundle depends on is not installed.

If I succeed in doing this, I will post an update to this question.

OK, I succeeded in running bundle install as the rails user (no sudo).

As the rvm documentation said, non-root users can install gems as needed in the system-wide Ruby if they are members of the rvm group. All you have to do is, as root, execute this command:

gpasswd -a rails rvm

After that, everything should work. The reason I was getting errors after that was that I am using the smallest droplet size and it was running out of memory. I created a temporary swap file (see this article for information about how to do that) and everything worked without problems.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.