Intro

After spending about 1 1/2 years building my prototype website I am finally ready to push my code to a demo server to help with potential client presentations. Right now, my project is hosted on github.com and they recommended an application known as ‘Capistrano’ to deploy code to remote servers. This article will outline the numerous roadblocks I had to go through, and try to piece various solutions into one location so other devs who are wanting to use Capistrano to deploy code will not have to navigate the same trials and tribulations that I did.

Before I start into how to setup Ruby, RubyGems, and Capistrano on CentOS, I’d like to define each one, so you have a clear understanding of why you need them to accomplish the final goal.

– Update 12.7.2011 –
If you are running into a “it seems your ruby installation is missing psych” message when running ruby, check out my post on how to resolve the issue: http://melikedev.com/2011/12/07/linux-centos6-ruby-it-seems-your-ruby-installation-is-missing-psych/

Ruby

http://www.ruby-lang.org/en/

As defined by the official Ruby website; “A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.”

Why do we need Ruby? Because Capistrano is written in Ruby.

RubyGems

http://rubygems.org/

RubyGems is a repo for Ruby Apps, much like Yum for CentOs. Even though we could download source and compile outside of RubyGems, I preferred to go through RubyGems to ensure a higher probability of system stability.

Capistrano

http://rubygems.org/gems/capistrano (source via rubygems)

https://github.com/capistrano/capistrano (source via github.com)

As defined by Capistrano website; “Capistrano is a utility and framework for executing commands in parallel on multiple remote machines, via SSH”

Basically, Capistrano will execute a series of commands on remote machines using a highly configurable config file.

Can’t use YUM for Ruby

So this is where I spent a lot of time trying Capistrano to work on my system. I wanted to use Yum to manage the Ruby install, but as you probably know, CentOs is very stable, and this stability derives from the fact that applications spend years in a specific version, and Ruby is no exception. If you use yum to install Ruby, you will find that it is current up to version 1.8.5, however we need version 1.8.6+ (for RubyGems to work correctly).

So I tried to use a “ruby” repo as outlined in various postings scattered throughout Google. In essence they each said you can create a “Ruby” repo using the following config:

vi /etc/yum.repos.d/ruby.repo
1
name=ruby
baseurl=http://repo.premiumhelp.eu/ruby/
gpgcheck=0
enabled=0

Now, in theory, you can type the following command:

yum --enablerepo=ruby list *RUBY*

I experienced a lot of frustration with this part because it kept listing out the default version (1.8.5) and I couldn’t figure out why. After a few hours and some tinkering I realized that in my /etc/yum.conf file I had set my excludes to exclude everything except 64 bit applications. Guess what? Ruby via the “Ruby” repo is not a 64 bit application so it wasn’t showing up. So I tried the following:

yum list *RUBY* --enablerepo=ruby --disableexcludes=all

Sure enough I finally saw Ruby version 1.8.6 listed, so I told Yum to install it and ran into yet another roadblock. The i686 version of Ruby wanted to install another 44 packages (dependencies) that were also i686. No way did I want to bork my stable system with 2 versions of common dependencies or reduce performance by downgrading from a 64 bit app to a 32 bit app. At the end of the day I was left with only one choice; download source and compile.

Compile and Install Ruby from Source

Simple enough:


cd /usr/local/source

wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p174.tar.gz

tar -xzvf ruby-1.8.7-p174.tar.gz

cd ruby-1.8.7-p174

./configure

make

make install

ruby --version

Now, if installed correctly ruby should return: “ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]“. Sweet, now we can move onto RubyGems.

Install RubyGems

Installing rubygems is easier than having to compile from source because now that you have Ruby installed you can use it to do the install for you:


cd /usr/local/src

wget http://production.cf.rubygems.org/rubygems/rubygems-1.4.1.tgz

tar -xzvf rubygems-1.4.1.tgz

cd rubygems-1.4.1

ruby setup.rb

RubyGems should now be installed, now onto Capistrano.

Install Capistrano

Installing Capistrano is even easier than installing Ruby or RubyGems:

gem install capistrano

After install completes you can go to your html source and type:

 capify .

Which will create a config file (config/deploy.rb).

Configure Capistrano

Configuring your deploy config will be covered in another article soon to come.

Closing

Now you have Ruby, RubyGems, and Capistrano installed on your CentOS server and after some configuration setup will be able to start pushing your code to remote servers.

Hope this article helped.