First, let me preface this article with the fact that I am not a ruby developer, on rails or off. 🙂 I’m an administrator that regularly is asked to help provide the environment for Ruby on Rails developers to work in. With that caveat out of the way, let’s get to it, shall we?

This was tested on Redhat 5.10 and 6.5. By extension, that means that it should install pretty painlessly on CentOS and Fedora as well using these instructions. As for others (Ubuntu, Debian, etc), you should be able to generally follow this article and apply it to other distributions with a few changes to what you use for your package manager.

Let’s do this.

Step one: Ruby

I’m going to make a pitch here that I don’t normally make. Use the Ruby Version Manager. There’s a couple of reasons. The first being that Redhat is pretty notorious for behing behind on the current version and of all the developers I deal with, Ruby folks tend to be the ones that push the hardest for the most current version. RVM makes installing the most current version pretty painless. Additionally? RVM allows you to have muliple versions installed and switch between them in an incredibly painless way:

(~) # rvm list rubies

rvm rubies

=* ruby-1.9.3-p448 [ x86_64 ]
ruby-2.1.1 [ x86_64 ]

# => - current
# =* - current && default
# * - default
(~) # ruby --version
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]
(~) # rvm use 2.1.1 --default
(~) # ruby --version
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
(~) # rvm use 1.9.3-p448 --default
(~) # ruby --version
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]

So, while this does take Ruby out of the automatic RHN updates, I feel that it adds benefits in the ease of updates and rollbacks that make it worth it. Just make sure that you (or your client) are aware that you MUST stay on top of Ruby updates. It will not happen “automagically” anymore.

To install the Ruby Version Manager and the current ruby (2.1.1 at the time of this article):

1) yum install curl epel-release
2) curl -L get.rvm.io | bash -s stable
3) source /etc/profile.d/rvm.sh
4) rvm requirements
5) rvm install 2.1.1
6) rvm use 2.1.1 –default
7) rvm rubygems current

Some commands to view the installed environment:

rvm list rubies
rvm list default

There are others. The manpage has more details.

Next up, install Rails:

yum install sqlite-devel nodejs
gem update
gem update –system
gem install rails

That last step WILL take a while to complete. Particularly for the docs. If you’re nervous about long hanging commands with no output… throw the verbose tag at it to have more output.

From there, you can create your first rails application and test it if you want. I’m not really going to go down that path (again, I’m not a ruby developer), but I may write another quick article tomorrow about how to create a basic app and test it without having to involve apache, mongrel, or passenger.

From there, you have a couple of options on how to serve your Ruby on Rails apps.

Mongrel

Mongrel is a web server written in Ruby that is designed to serve these apps. You can install it pretty painlessly:

gem install mongrel mongrel_cluster

A good article on how mongrel works, even though it is a bit out of date, can be read here:
http://articles.slicehost.com/2009/4/17/centos-mongrel-and-mongrel-clusters

Passenger

Passenger is a web/app server that integrates into apache via a module. A lot of our clients opt for this because of the seamless integration with the already very familiar apache syntax. Passenger is a little more involved to install, but you end up with a solution that allows you to use apache sytax, so it may be worth it in the long run.

gem install passenger
yum install curl-devel httpd-devel apr-devel apr-util-devel
passenger-install-apache2-module

That last command will set up a curses script that verifies your environment, asks you questions, etc. Provided you do the yum install command I’ve provided, it should be pretty automatic. Once it is done, you will get output like:

LoadModule passenger_module /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.38/buildout/apache2/mod_passenger.so

PassengerRoot /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.38
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.1.1/wrappers/ruby

I’d stick this in /etc/httpd/conf.d/passenger.conf.

It will also provide you an example vhost for itegrating your Ruby on Rails app:

Deploying a web application: an example

Suppose you have a web application in /somewhere. Add a virtual host to your
Apache configuration file and set its DocumentRoot to /somewhere/public:

<VirtualHost *:80>
ServerName www.yourhost.com
# !!! Be sure to point DocumentRoot to ‘public’!
DocumentRoot /somewhere/public
<Directory /somewhere/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>

And that’s it, really. At least from the server administrator’s point of view. There’s a whole lot more that continues out from here on the development side of things. 🙂


Category: ruby

Leave a Reply

Categories


gives good tech

tech.superhappykittymeow.com
Kale is one of the smartest people I know

Racker Hacker
Major is always good for leet deetz