How to Install a Ruby Gem Server

How to Install a Ruby Gem Server

There are numerous reasons it is beneficial to have your own gem server including controlling the versions of various gems deployed to all of your servers. Below is a brief explanation of how to install a gem server on your local network.

1. Install Web Server: If you do not already have a web server installed then install LiteSpeed or Apache

A. Install Apache:
[root@server ~]#yum install httpd

B. Modify Config: If you have a domain you want to use then:
[root@server ~]#vi /etc/httpd/conf/httpd.conf

i. Turn on NameVirtualHost:
[root@server ~]#NameVirtualHost *:80

ii. Edit Virtual Host Settings: Modify your virtual host something like the below:
[root@server ~]#VirtualHost
DocumentRoot /var/www/html/rubygems
ErrorLog logs/
CustomLog logs/ common

C. Make Gem Server Root and Gems Directory:
[root@server ~]#mkdir /var/www/html/rubygemsmkdir
mkdir /var/www/html/rubygems/gems

D. Make Apache start on server reboot:
[root@server ~]#chkconfig httpd on

E. Start Apache:
[root@server ~]#/etc/init.d/httpd start

2. Install Ruby:
A. Get the latest version of Ruby from here.
B. Download to your server:
[root@server ~]#cd /usr/local/src
wget http://link-to-your-ruby-package

C. Unpack the ruby source:
[root@server ~]#tar -zxvf ruby-1.8.6-p286.tar.gz

D. Configure, Make, and Install:
[root@server ~]#cd /usr/local/src/ruby-1.8.6-p286
/configure –prefix=/usr/local
make install

3. Install RubyGems:
A. Get the latest version of rubygems from here.
B. Download to your server:
[root@server ~]#cd /usr/local/src
wget http://link-to-rubygems-package

C. Unpack the rubygems source:
[root@server ~]#tar -zxvf rubygems-1.2.0.tgz

D. Configure and Install:
[root@server ~]#cd /usr/local/src/rubygems-1.2.0
ruby setup.rbv

4. Make Gems Available: Install any gems you want to provide to your other servers and then put them in the correct directory
A. Install Gems:
[root@server ~]#gem install ar_mailer

B. See Gems:
[root@server ~]#gem list

C. Make Gems Available: Copy your .gem files into your servers new gem direcotry:
[root@server ~]#cp -p ar_mailer.gem /var/www/html/rubygems/gems

D. Prepare Gem Server:
[root@server ~]#gem generate_index -d /var/www/html/rubygems

5. Point Servers To New Gem Server:

**Note: If you don’t already have rubygems 1.2.0 or greater installed on your client server then upgrade following step A if not skip to step B.

A. Update rubygems:
[root@server ~]#gem update –system

B. List Current Gem Sources:
[root@server ~]#gem sources –list

C. Add Your Gem Server:
[root@server ~]#gem sources –add

D. Remove Other Sources:
[root@server ~]#gem sources –remove

**Note** Make sure to have the trailing “/” on the end of the or it will not be removed.