Best practices for using RVM to run Ruby on Rails 5 on a web server

208 views Asked by At

I realize that this question has already been asked a million times, but after days of searching I am still yet to find a suitable answer.

I would like to run Ruby on Rails 5 on Centos 7. The default Ruby currently packaged with Centos 7 is 2.0.0. For Rails 5, I need a higher version, hence the need for RVM.

Here are some of the problems I have encountered when using RVM:

  1. If I use the recommended option to install RVM

    \curl -sSL https://get.rvm.io | bash -s stable --ruby
    

    RVM and all Ruby gems will install into my $HOME directory, but this is not ideal, because the server has many users, and, since it is a web server, it is, of course, not desirable to have gems contained with users' home directories, especially if those directories could be deleted at any time (if an employee's contract ends).

  2. Some people recommend installing RVM using sudo to get around that problem (though just as many people frown on this approach, as it seems to negate the purpose of RVM):

    \curl -sSL https://get.rvm.io | sudo bash -s stable --ruby
    

    and based on RVM's own suggestion, I comment out the line containing

    Defaults secure_path=...
    

    and my gems are installed into /usr/local/rvm/gems/ruby-2.3.1, which is great, except it produces another problem:

    • If I run gem install rails I receive an error:

      You don't have write permissions for the /usr/local/rvm/gems/ruby-2.3.1 directory.
      

      Yes, I could solve this by adding myself to the rvm group, but this is not ideal, because that means I always have to remember to add every new user to and remove every old user from this group.

    • If I run sudo gem install rails I also receive an error:

      /usr/bin/env: ruby: No such file or directory
      
    • If I run rvmsudo gem install rails, everything works, except I will also have to run bundle install using rvmsudo, which produces a warning, because it is not recommended.

    • I could run everything using root user, which works... but then I need to remember to change the owner of all of my project files because apache doesn't quite have root privileges and is unable to write to certain of the project's directories. Plus, running as root seems wrong on so many levels.


In other words, no matter what approach I choose while using RVM, I run into one problem or another. Perhaps, someone else who has deployed this successfully can share their insights.

The only reasonable approach I have been able to come up with is to create a dedicated Rails user, to which all server users would switch prior to performing any maintenance, but I am worried that a service like apache won't "see" the gems installed locally.

Comments, thoughts, ideas? Maybe there is something I am missing about RVM?

0

There are 0 answers