Entries Tagged 'Ruby' ↓

Howto install RMagick 2 on CentOS/RHEL 5

Installing RMagick 2 on CentOS/RHEL 5 it’s not that hard, you just need to install ImageMagick newer than 6.3.5 (CentOS/RHEL 5 is shipping ImageMagick 6.2.8) and that’s the hardest part of the job.

[root@silver ~]# gem install rmagick
Building native extensions.  This could take a while...
ERROR:  Error installing rmagick:
        ERROR: Failed to build gem native extension.
 
/usr/local/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... yes
checking for ImageMagick version >= 6.3.5... no
Can't install RMagick 2.12.2. You must have ImageMagick 6.3.5 or later.

I’ve tried to avoid ImageMagick upgrade and to install RMagick 1, but RMagick 1 failed to install with a strange compile error, probably because the gcc compliler shipped with CentOS/RHEL 5 is too new for version 1.

I didn’t wanted to patch RMagick 1, neither to install from sources (I do prefer RPM packages). So, I’ve decided to upgrade ImageMagick library to satisfy RMagick 2 requirements.

Subscribe your system to the following repositories:

Install the following packages:

[root@silver ~]# yum --enablerepo=epel --enablerepo=rpmforge --enablerepo=centosplus install djvulibre-devel libwmf-devel jasper-devel libtool-ltdl-devel librsvg2-devel openexr-devel graphviz-devel gcc gcc-c++ ghostscript freetype-devel libjpeg-devel libpng-devel giflib-devel libwmf-devel libexif-devel libtiff-devel

Add “–noplugins” if you are using “yum-priorities”, or it will fail to install packages.

Download ImageMagick.spec to your SPECS directory and ImageMagick-6.5.7-0.tar.bz2 to SOURCES directory and then rebuild the rpm using rpmbuild:

[root@silver SPECS]# rpmbuild -ba ImageMagick.spec
 
[...]

Or just grab the source RPM from here:
http://red.penguin.ro/SRPMS/ImageMagick-6.5.7-0.src.rpm

and build it:

[root@silver ~]# rpmbuild --rebuild ImageMagick-6.5.7-0.src.rpm 
Installing ImageMagick-6.5.7-0.src.rpm
warning: user vitalie does not exist - using root
warning: group vitalie does not exist - using root
warning: user vitalie does not exist - using root
warning: group vitalie does not exist - using root
Executing(%prep): /bin/sh -e /home/worf/rpmbuild/tmp/rpm-tmp.11936
+ umask 022
+ cd /home/worf/rpmbuild/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /home/worf/rpmbuild/BUILD
+ rm -rf ImageMagick-6.5.7-0
+ /usr/bin/bzip2 -dc /home/worf/rpmbuild/SOURCES/ImageMagick-6.5.7-0.tar.bz2
+ tar -xf -
 
[...]
 
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires: /bin/sh ImageMagick-c++ = 6.5.7-0 ImageMagick-devel = 6.5.7-0 libMagick++.so.2()(64bit)
Processing files: ImageMagick-debuginfo-6.5.7-0
Provides: Magick.so.debug()(64bit) analyze.so.debug()(64bit) art.so.debug()(64bit) avi.so.debug()(64bit) avs.so.debug()(64bit) bmp.so.debug()(64bit) braille.so.debug()(64bit) cals.so.debug()(64bit) caption.so.debug()(64bit) cin.so.debug()(64bit) cip.so.debug()(64bit) clip.so.debug()(64bit) cmyk.so.debug()(64bit) cut.so.debug()(64bit) dcm.so.debug()(64bit) dds.so.debug()(64bit) dib.so.debug()(64bit) djvu.so.debug()(64bit) dng.so.debug()(64bit) dot.so.debug()(64bit) dpx.so.debug()(64bit) ept.so.debug()(64bit) fax.so.debug()(64bit) fits.so.debug()(64bit) gif.so.debug()(64bit) gradient.so.debug()(64bit) gray.so.debug()(64bit) hald.so.debug()(64bit) histogram.so.debug()(64bit) hrz.so.debug()(64bit) html.so.debug()(64bit) icon.so.debug()(64bit) info.so.debug()(64bit) inline.so.debug()(64bit) ipl.so.debug()(64bit) jp2.so.debug()(64bit) jpeg.so.debug()(64bit) label.so.debug()(64bit) libMagick++.so.2.0.0.debug()(64bit) libMagickCore.so.2.0.0.debug()(64bit) libMagickWand.so.2.0.0.debug()(64bit) magick.so.debug()(64bit) map.so.debug()(64bit) mat.so.debug()(64bit) matte.so.debug()(64bit) meta.so.debug()(64bit) miff.so.debug()(64bit) mono.so.debug()(64bit) mpc.so.debug()(64bit) mpeg.so.debug()(64bit) mpr.so.debug()(64bit) msl.so.debug()(64bit) mtv.so.debug()(64bit) mvg.so.debug()(64bit) null.so.debug()(64bit) otb.so.debug()(64bit) palm.so.debug()(64bit) pattern.so.debug()(64bit) pcd.so.debug()(64bit) pcl.so.debug()(64bit) pcx.so.debug()(64bit) pdb.so.debug()(64bit) pdf.so.debug()(64bit) pict.so.debug()(64bit) pix.so.debug()(64bit) plasma.so.debug()(64bit) png.so.debug()(64bit) pnm.so.debug()(64bit) preview.so.debug()(64bit) ps.so.debug()(64bit) ps2.so.debug()(64bit) ps3.so.debug()(64bit) psd.so.debug()(64bit) pwp.so.debug()(64bit) raw.so.debug()(64bit) rgb.so.debug()(64bit) rla.so.debug()(64bit) rle.so.debug()(64bit) scr.so.debug()(64bit) sct.so.debug()(64bit) sfw.so.debug()(64bit) sgi.so.debug()(64bit) stegano.so.debug()(64bit) sun.so.debug()(64bit) svg.so.debug()(64bit) tga.so.debug()(64bit) thumbnail.so.debug()(64bit) tiff.so.debug()(64bit) tile.so.debug()(64bit) tim.so.debug()(64bit) ttf.so.debug()(64bit) txt.so.debug()(64bit) uil.so.debug()(64bit) url.so.debug()(64bit) uyvy.so.debug()(64bit) vicar.so.debug()(64bit) vid.so.debug()(64bit) viff.so.debug()(64bit) wbmp.so.debug()(64bit) wmf.so.debug()(64bit) wpg.so.debug()(64bit) x.so.debug()(64bit) xbm.so.debug()(64bit) xc.so.debug()(64bit) xcf.so.debug()(64bit) xpm.so.debug()(64bit) xps.so.debug()(64bit) xwd.so.debug()(64bit) ycbcr.so.debug()(64bit) yuv.so.debug()(64bit)
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/worf/rpmbuild/tmp/ImageMagick-6.5.7-0-root-root
Wrote: /home/worf/rpmbuild/RPMS/x86_64/ImageMagick-6.5.7-0.x86_64.rpm
Wrote: /home/worf/rpmbuild/RPMS/x86_64/ImageMagick-devel-6.5.7-0.x86_64.rpm
Wrote: /home/worf/rpmbuild/RPMS/x86_64/ImageMagick-doc-6.5.7-0.x86_64.rpm
Wrote: /home/worf/rpmbuild/RPMS/x86_64/ImageMagick-perl-6.5.7-0.x86_64.rpm
Wrote: /home/worf/rpmbuild/RPMS/x86_64/ImageMagick-c++-6.5.7-0.x86_64.rpm
Wrote: /home/worf/rpmbuild/RPMS/x86_64/ImageMagick-c++-devel-6.5.7-0.x86_64.rpm
Wrote: /home/worf/rpmbuild/RPMS/x86_64/ImageMagick-debuginfo-6.5.7-0.x86_64.rpm
Executing(%clean): /bin/sh -e /home/worf/rpmbuild/tmp/rpm-tmp.25482
+ umask 022
+ cd /home/worf/rpmbuild/BUILD
+ cd ImageMagick-6.5.7-0
+ rm -rf /home/worf/rpmbuild/tmp/ImageMagick-6.5.7-0-root-root
+ exit 0
Executing(--clean): /bin/sh -e /home/worf/rpmbuild/tmp/rpm-tmp.25482
+ umask 022
+ cd /home/worf/rpmbuild/BUILD
+ rm -rf ImageMagick-6.5.7-0
+ exit 0

Uninstall i386 ImageMagick libraries if you are on x86_64 system:

[root@silver ~]# rpm -qa | grep ImageMagick | grep -i i386 | xargs rpm -e

Install the new RPMs compiled in the previous steps:

[root@silver x86_64]# rpm -Uvh ImageMagick-6.5.7-0.x86_64.rpm ImageMagick-c++-6.5.7-0.x86_64.rpm ImageMagick-c++-devel-6.5.7-0.x86_64.rpm ImageMagick-devel-6.5.7-0.x86_64.rpm

Finally, install the RMagick 2 plugin:

[root@silver ~]# gem install rmagick --no-rdoc --no-ri
Building native extensions.  This could take a while...
Successfully installed rmagick-2.12.2
1 gem installed

Ruby Enterprise Edition 1.8.7 source RPM for CentOS5 / RHEL5

Ruby Enterprise Edition is a server-oriented friendly branch of Ruby which includes various enhancements:

* A copy-on-write friendly garbage collector. Phusion Passenger uses this, in combination with a technique called preforking, to reduce Ruby on Rails applications’ memory usage by 33% on average.
* An improved memory allocator called tcmalloc, which improves performance quite a bit.
* The ability to tweak garbage collector settings for maximum server performance, and the ability to inspect the garbage collector’s state. (RailsBench GC patch)
* The ability to dump stack traces for all running threads (caller_for_all_threads), making it easier for one to debug multithreaded Ruby web applications.

More on Ruby Enterprise Edition’s website:
http://www.rubyenterpriseedition.com/

Download source rpm:
ruby-enterprise-1.8.7-1.el5.src.rpm

Build rpm package using rpmbuild:

[vitalie@silver SRPMS]$ rpmbuild --rebuild --define 'dist el5' ruby-enterprise-1.8.7-1.el5.src.rpm 
Installing ruby-enterprise-1.8.7-1.el5.src.rpm
Executing(%prep): /bin/sh -e /home/vitalie/rpmbuild/tmp/rpm-tmp.89437
+ umask 022
+ cd /home/vitalie/rpmbuild/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /home/vitalie/rpmbuild/BUILD
+ rm -rf ruby-enterprise-1.8.7-20090928
+ /bin/gzip -dc /home/vitalie/rpmbuild/SOURCES/ruby-enterprise-1.8.7-20090928.tar.gz
+ tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd ruby-enterprise-1.8.7-20090928
++ /usr/bin/id -u
+ '[' 500 = 0 ']'
++ /usr/bin/id -u
+ '[' 500 = 0 ']'
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /home/vitalie/rpmbuild/tmp/rpm-tmp.89437
+ umask 022
+ cd /home/vitalie/rpmbuild/BUILD
+ cd ruby-enterprise-1.8.7-20090928
+ LANG=C
+ export LANG
+ unset DISPLAY
+ ./installer --auto /usr/local --dont-install-useful-gems --destdir /home/vitalie/rpmbuild/tmp/ruby-enterprise-1.8.7-20090928-root-vitalie
 
[...]
 
Provides: ruby-enterprise(rubygems) = 1.3.2
Requires(interp): /bin/sh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(VersionedDependencies) <= 3.0.3-1
Requires(pre): /bin/sh
Requires: /usr/local/bin/ruby ruby-enterprise >= 1.8
Processing files: ruby-enterprise-debuginfo-1.8.7-1.el5
Provides: bigdecimal.so.debug()(64bit) bubblebabble.so.debug()(64bit) cparse.so.debug()(64bit) curses.so.debug()(64bit) dbm.so.debug()(64bit) digest.so.debug()(64bit) dl.so.debug()(64bit) etc.so.debug()(64bit) fcntl.so.debug()(64bit) gdbm.so.debug()(64bit) iconv.so.debug()(64bit) libtcmalloc_minimal.so.0.0.0.debug()(64bit) md5.so.debug()(64bit) nkf.so.debug()(64bit) openssl.so.debug()(64bit) pty.so.debug()(64bit) readline.so.debug()(64bit) rmd160.so.debug()(64bit) sdbm.so.debug()(64bit) sha1.so.debug()(64bit) sha2.so.debug()(64bit) socket.so.debug()(64bit) stringio.so.debug()(64bit) strscan.so.debug()(64bit) syck.so.debug()(64bit) syslog.so.debug()(64bit) thread.so.debug()(64bit) wait.so.debug()(64bit) zlib.so.debug()(64bit)
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/vitalie/rpmbuild/tmp/ruby-enterprise-1.8.7-20090928-root-vitalie
Wrote: /home/vitalie/rpmbuild/RPMS/x86_64/ruby-enterprise-1.8.7-1.el5.x86_64.rpm
Wrote: /home/vitalie/rpmbuild/RPMS/x86_64/ruby-enterprise-rubygems-1.3.2-1.el5.x86_64.rpm
Wrote: /home/vitalie/rpmbuild/RPMS/x86_64/ruby-enterprise-debuginfo-1.8.7-1.el5.x86_64.rpm
Executing(%clean): /bin/sh -e /home/vitalie/rpmbuild/tmp/rpm-tmp.76776
+ umask 022
+ cd /home/vitalie/rpmbuild/BUILD
+ cd ruby-enterprise-1.8.7-20090928
+ rm -rf /home/vitalie/rpmbuild/tmp/ruby-enterprise-1.8.7-20090928-root-vitalie
+ exit 0
Executing(--clean): /bin/sh -e /home/vitalie/rpmbuild/tmp/rpm-tmp.76776
+ umask 022
+ cd /home/vitalie/rpmbuild/BUILD
+ rm -rf ruby-enterprise-1.8.7-20090928
+ exit 0

Alternatively you can download just spec file and grab sources from the REE’s website:
ruby-enterprise.spec

PageActions Plugin released

I’ve just released PageActions plugin on GitHub. It’s a really simple Rails plugin, but it helps you to easy define and render actions links in your views. You can view installation and usage instructions on GitHub:


http://github.com/vitalie/page_actions

Iteration over large data sets in Rails

We often need to iterate over the database rows in our migrations. When dealing with millions of records, basic iteration techniques doesn’t work well because each loaded object is consuming system memory and it issues at least one database query per object to load.

# >> Book.count :all
# => 4000216

Solution 1

class BooksUpdateTitles < ActiveRecord::Migration
  def self.up
    Books.all.each do |book|
      # ...
    end
  end
 
  def self.down
  end
end

The problem with this version is that it will load all 4000216 objects into memory, all memory will be consumed and it will start to use disk swap and it will take hours to complete.

We can optimize it a little bit by specifying select parameter in our query:

Solution 2

Books.find(:all, :select => 'id').each do |t|
  book = Book.find t.id
  # ...
end

Version 2 still loads all objects in memory but selects only id field.

We need to avoid loading all objects in the memory, we’ll iterate over collection and we’ll load only current object.

Solution 3

last_id = 0
while book = Books.find(:first, :conditions => ['id > ?', last_id])
  # ...
  last_id = book.id
end

Version 3 it’s OK, but it can be speed up by loading objects in batch not just one by one.

Solution 4

last_id = 0
while books = Book.find(:all, :conditions => ['id > ?', last_id], :limit => 100)
  # ...
  last_id = books.last.id
end

Examining the log:

...
Domain LOAD (0.000176)  SELECT * FROM `books` WHERE (id > 0) LIMIT 100
...

We have loaded 100 objects with one query. Solution 4 seems to be the best solution to iterate over large data sets as it uses less memory with fewer SQL requests.

Update:

Mitchell proposed a better solution to use ActiveRecord’s find_in_batches method. DHH commited this feature on February 23, 2009 that permits iterating over large data sets in batches:

Read more:
WebOnRails
GitHub

Solution 5

Book.find_in_batches(:batch_size => 100) do |results|
# Do something with results
end

Hpricot 0.8.1 on ruby 1.8.5

Installing latest Hpricot on ruby 1.8.5 fails due missing macro RARRAYPTR:

[root@silver ~]# gem install hpricot
Building native extensions.  This could take a while...
ERROR:  Error installing hpricot:
        ERROR: Failed to build gem native extension.
 
/usr/bin/ruby extconf.rb
checking for main() in -lc... yes
creating Makefile
 
make
gcc -I. -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I.  -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wall -fno-strict-aliasing  -fPIC  -c hpricot_css.c
hpricot_css.rl: In function ‘hpricot_css’:
hpricot_css.rl:106: warning: implicit declaration of function ‘RSTRING_PTR’
hpricot_css.rl:106: warning: assignment makes pointer from integer without a cast
hpricot_css.rl:107: warning: implicit declaration of function ‘RSTRING_LEN’
hpricot_css.rl:82: warning: field precision should have type ‘int’, but argument 5 has type ‘long int’
hpricot_css.c:295: warning: comparison is always true due to limited range of data type
[...]
hpricot_css.c:3403: warning: comparison between pointer and integer
hpricot_css.c:3403: warning: ‘eof’ is used uninitialized in this function
hpricot_css.rl:92: warning: ‘aps’ may be used uninitialized in this function
gcc -I. -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I.  -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wall -fno-strict-aliasing  -fPIC  -c hpricot_scan.c
hpricot_scan.rl: In function ‘our_rb_hash_lookup’:
hpricot_scan.rl:169: warning: implicit declaration of function ‘st_lookup’
hpricot_scan.rl: In function ‘make_hpricot_struct’:
hpricot_scan.rl:693: warning: implicit declaration of function ‘RARRAYPTR’
hpricot_scan.rl:693: error: subscripted value is neither array nor pointer
make: *** [hpricot_scan.o] Error 1
 
 
Gem files will remain installed in /usr/lib64/ruby/gems/1.8/gems/hpricot-0.8.1 for inspection.
Results logged to /usr/lib64/ruby/gems/1.8/gems/hpricot-0.8.1/ext/hpricot_scan/gem_make.out

Searching with google I’ve found this post that explains equivalence of the RARRAYPTR(v) is RARRAY(v)->ptr . We’ll need to define RARRAYPTR macro.

We’ll replace occurences of #include <ruby.h> with #include “ruby_macros.h” and create an include file ruby_macros.h with the following content:

#ifndef __RUBY_MACROS__
#define __RUBY_MACROS__
 
#include <ruby.h>
 
#ifndef RARRAYPTR
#  define RARRAYPTR(v) RARRAY(v)->ptr
#endif
#endif
[root@silver ~]# cd /usr/lib64/ruby/gems/1.8/gems/hpricot-0.8.1/ext/hpricot_scan 
[root@silver hpricot_scan]# sed -i 's,#include <ruby.h>,#include "ruby_macros.h",g' *.h *.c *.rl
[root@silver hpricot_scan]# touch ruby_macros.h
[root@silver hpricot_scan]# vi ruby_macros.h

The next step is to recreate the gem and install it:

[root@silver ~]# cd /usr/lib64/ruby/gems/1.8/gems/hpricot-0.8.1
[root@silver hpricot-0.8.1]# rake package
(in /usr/lib64/ruby/gems/1.8/gems/hpricot-0.8.1)
fatal: Not a git repository
rm -r ext/fast_xs/Makefile
rm -r ext/hpricot_scan/Makefile
rm -r .config
rm -r pkg
rm -r hpricot-0.8.1-mswin32
rm -r hpricot-0.8.1-jruby
Using ragel version: 6.3, location: /usr/bin/ragel
cd ext/hpricot_scan ; ragel hpricot_scan.rl -G2 -o hpricot_scan.c && ragel hpricot_css.rl -G2 -o hpricot_css.c
mkdir -p pkg
mkdir -p pkg/hpricot-0.8.1
rm -f pkg/hpricot-0.8.1/CHANGELOG
[...]
cd pkg
tar zcvf hpricot-0.8.1.tgz hpricot-0.8.1
hpricot-0.8.1/
hpricot-0.8.1/Rakefile
[...]
hpricot-0.8.1/ext/fast_xs/fast_xs.c
cd -
WARNING:  description and summary are identical
  Successfully built RubyGem
  Name: hpricot
  Version: 0.8.1
  File: hpricot-0.8.1.gem
mv hpricot-0.8.1.gem pkg/hpricot-0.8.1.gem
[root@silver hpricot-0.8.1]# gem install pkg/hpricot-0.8.1.gem
Building native extensions.  This could take a while...
Successfully installed hpricot-0.8.1
1 gem installed
Installing ri documentation for hpricot-0.8.1...
Installing RDoc documentation for hpricot-0.8.1...
 
[root@silver hpricot_scan]# gem list -l | grep hpricot
hpricot (0.8.1, 0.7, 0.6.164, 0.6.161, 0.6)

Simple script to convert ERB files to Haml

A simple script to convert .erb files from current directory to .haml :

#!/usr/bin/ruby
 
Dir.glob("*.html.erb").each do |erbname|
  hamlname = erbname.gsub(".html.erb", ".html.haml")
  system "/usr/bin/html2haml #{erbname} #{hamlname}"
end

File uploads in import scripts

Simulating file uploads in your scripts or from console can be done really simple using Rail’s ActionController::TestUploadedFile from action_pack.

Example code:

require 'action_controller/test_process'
 
class ImportExternalData
 ...
  def import_data
    ...
    page.attachments << PageAttachment.new(
      :uploaded_data => fake_file_upload(filename, mime_type),
      :title => title,
      :description => description)
    ...
  end
 
 
protected
  def fake_file_upload(path, mime_type = nil, binary = false)
    ActionController::TestUploadedFile.new(
      path,
      mime_type,
      binary
    )
  end
end

Excerpt from ActionController::TestUploadedFile’s comments:

Essentially generates a modified Tempfile object similar to the object
you’d get from the standard library CGI module in a multipart
request. This means you can use an ActionController::TestUploadedFile
object in the params of a test request in order to simulate
a file upload.

Howto install RMagick on CentOS 4

RMagick is an interface between the Ruby programming language and the ImageMagick® and GraphicsMagick image processing libraries.

To install RMagick on CentOS 4 you’ll need to install RMagick version 1 because version 2 requires newer version of ImageMagick that’s not available in CentOS 4 repositories.

I do assume that you already have installed RubyGems. If not, then read my post Install RubyGems on CentOS 4.

Let’s start by installing required libraries:

[root@lion ~]# yum  install gcc gcc-c++ ImageMagick-devel ghostscript freetype-devel \ 
                         libjpeg-devel libpng-devel libpng10-devel libwmf-devel libexif-devel libtiff-devel
[...]

Then install RMagick gem specifying version with ‘-v’ switch:

[root@lion ~]# gem install rmagick -v 1.15.14 
Building native extensions.  This could take a while...
Successfully installed rmagick-1.15.14
1 gem installed

Install RubyGems on CentOS 4

This post will explain how to install RubyGems 1.2 on the server running CentOS 4.

Following instructions from the install section of the RubyGems User Guide:

http://www.rubygems.org/read/chapter/3

[root@monster tmp]# yum -y install ruby ruby-devel irb
...
[root@monster tmp]# wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
...
[root@monster tmp]# tar xvfzp rubygems-1.2.0.tgz
...
[root@monster tmp]# cd rubygems-1.2.0
[root@monster rubygems-1.2.0]# ruby setup.rb 
Expected Ruby version > 1.8.3, was 1.8.1

Oops, we’ll need a newer version of ruby, by default CentOS 4 comes with ruby 1.8.1 . To install a newer version of ruby we’ll subscribe to testing repository from CentOS. To do this we’ll create a repo file called CentOS-Testing.repo in /etc/yum.repos.d directory:

CentOS-Testing.repo content

# /etc/yum.repos.d/CentOS-Testing.repo
# packages in testing repository
[testing]
name=CentOS-$releasever - Testing
baseurl=http://dev.centos.org/centos/$releasever/testing/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing

Note the line with enabled=0, we’ll enable the repository only when needed. Install ruby from the testing repository:

[root@monster ~]# yum --enablerepo=testing install ruby ruby-devel ruby-libs ruby-irb ruby-rdoc 
Loading "fastestmirror" plugin
Setting up Install Process
Setting up repositories
Loading mirror speeds from cached hostfile
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
...
Dependencies Resolved
 
=============================================================================
 Package                 Arch       Version          Repository        Size 
=============================================================================
Installing:
 ruby-irb                i386       1.8.5-5.el4.centos.1  testing            67 k
 ruby-rdoc               i386       1.8.5-5.el4.centos.1  testing           132 k
Updating:
 ruby                    i386       1.8.5-5.el4.centos.1  testing           272 k
 ruby-devel              i386       1.8.5-5.el4.centos.1  testing           503 k
 ruby-libs               i386       1.8.5-5.el4.centos.1  testing           1.5 M
 
Transaction Summary
=============================================================================
Install      2 Package(s)         
Update       3 Package(s)         
Remove       0 Package(s)         
Total download size: 2.5 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): ruby-rdoc-1.8.5-5. 100% |=========================| 132 kB    00:02     
(2/5): ruby-libs-1.8.5-5. 100% |=========================| 1.5 MB    00:14     
(3/5): ruby-devel-1.8.5-5 100% |=========================| 503 kB    00:04     
(4/5): ruby-1.8.5-5.el4.c 100% |=========================| 272 kB    00:03     
(5/5): ruby-irb-1.8.5-5.e 100% |=========================|  67 kB    00:01     
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating  : ruby-libs                    ######################### [1/9] 
  Updating  : ruby                         ######################### [2/9] 
  Installing: ruby-irb                     ######################### [3/9] 
  Installing: ruby-rdoc                    ######################### [4/9] 
  Updating  : ruby-devel                   ######################### [5/9] 
  Cleanup   : ruby-libs                    ######################### [6/9]
  Cleanup   : ruby-devel                   ######################### [7/9]
  Cleanup   : ruby                         ######################### [8/9]
  Removing  : irb                          ######################### [9/9]
 
Installed: ruby-irb.i386 0:1.8.5-5.el4.centos.1 ruby-rdoc.i386 0:1.8.5-5.el4.centos.1
Updated: ruby.i386 0:1.8.5-5.el4.centos.1 ruby-devel.i386 0:1.8.5-5.el4.centos.1 ruby-libs.i386 0:1.8.5-5.el4.centos.1
Complete!

Now it’s better, we do have ruby 1.8.5 installed on the system. Let’s return to RubyGems install:

[root@monster rubygems-1.2.0]# ruby setup.rb
...
------------------------------------------------------------------------------
 
RubyGems installed the following executables:
        /usr/bin/gem
 
If `gem` was installed by a previous RubyGems installation, you may need
to remove it by hand.

Voila! We have installed RubyGems 1.2 on the CentOS 4 server.