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

Posted July 14, 2015 3.1k views
Ruby on RailsUbuntuDigitalOcean 1-Click Apps Marketplace

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?

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.

Submit an Answer
4 answers

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.

by Justin Ellingwood
Swap space can be used as an "overflow" area for your system when you run out of RAM. The operating system can store data that would normally be kept in RAM on the hard drive in a specially formatted file. In this guide, we'll demonstrate how to create and use one of these files in Ubuntu 14.04.

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

sudo bundle install


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.

Good to hear you got it working. Using my ipad now but will check it out when im back home. Good luck with your ruby app