2007年8月16日木曜日

CentOSへRubyGemsをインストール

Rubyのインストールの次に。

Ruby on RailsをインストールするためにRubyの次に、RubyGemsの最新バージョンをインストール。

参考ページ
CentOS で構築する自宅サーバ

参考ページのまねで、checkinstall を使って RPM 化してからインストールする。

checkinstallを先に導入しておきます。

■RubyGemsの最新をインストール

2007年8月16日現在で最新バージョンはrubygems-0.9.4です。
最新版は RubyForgeで確認できます。

今回はwgetコマンドで最新バージョンをダウンロード
[root@mycentos ~]# wget http://rubyforge.org/frs/download.php/20989/rubygems-0.9.4.tgz


ソースの解凍、そしてできたディレクトリに移動します。
[root@mycentos ~]# tar zxvf rubygems-0.9.4.tgz
     ・
     ・
[root@mycentos ~]# cd rubygems-0.9.4


checkinstall を使って RPM 化します。
[root@mycentos rubygems-0.9.4]# checkinstall -R "ruby setup.rb"


以下の状態で止まります。デフォルトのパッケージドキュメントを作っていいかと聞かれます。作ってもいいのでそのまま Enter (デフォルトで Yes なので)を押します。
checkinstall 1.6.0, Cocheckinstall 1.6.0, Copyright 2002 Felipe Eduardo Sanchez Diaz Duran
This software is released under the GNU GPL.

The package documentation directory ./doc-pak does not exist.
Should I create a default set of package docs? [y]:


パッケージの詳細の入力を求められます。別によそに提供するわけでもないので、何も入力せずに Enter で良いそうです。
Preparing package documentation...OK
Please write a description for the package.
End your description with an empty line or EOF.>>


パッケージの内容の確認がでます。ここで は11を入力します。でEnter。
**************************************
**** RPM package creation selected ***
**************************************
This package will be built according to these values:
1 - Summary: [ Package created with checkinstall 1.6.0 ]2 - Name: [ rubygems ]3 - Version: [ 0.9.4 ]4 - Release: [ 1 ]5 - License: [ GPL ]6 - Group: [ Applications/System ]7 - Architecture: [ x86_64 ]8 - Source location: [ rubygems-0.9.4 ]9 - Alternate source location: [ ]10 - Requires: [ ]11 - Provides: [ rubygems ]
Enter a number to change any of them or press ENTER to continue:


Rubyと関連付けが必要なのでrubyと入力します。でEnter。

Enter a number to change any of them or press ENTER to continue:11
Enter the additional requirements: >>


最後にまた同じパッケージの内容の確認がでます。11のところがrubyになっているのが確認できます。
ここで Enter を押すと RPM の作成処理が始まります。
Enter the additional requirements: >>ruby

This package will be built according to these values:
1 - Summary: [ Package created with checkinstall 1.6.0 ]2 - Name: [ rubygems ]3 - Version: [ 0.9.4 ]4 - Release: [ 1 ]5 - License: [ GPL ]6 - Group: [ Applications/System ]7 - Architecture: [ x86_64 ]8 - Source location: [ rubygems-0.9.4 ]9 - Alternate source location: [ ]10 - Requires: [ ruby ]11 - Provides: [ rubygems ]
Enter a number to change any of them or press ENTER to continue:



RPM の作成処理が始まりました。うまくいきました。

Installing with ruby setup.rb...

========================= Installation results ===========================---> bin
<--- bin
---> lib
    ・
    ・
    ・
<--- lib/rubygems/digest
<--- lib/rubygems
<--- lib
Successfully built RubyGem
Name: sources
Version: 0.0.1
File: sources-0.0.1.gem
Removing old RubyGems RDoc and ri...
Installing rubygems-0.9.4 ri...
Installing rubygems-0.9.4 rdoc...

As of RubyGems 0.8.0, library stubs are no longer needed.
Searching $LOAD_PATH for stubs to optionally delete (may take a while)...
...done.
No library stubs found.


======================== Installation successful ==========================
Copying documentation directory...
./
./TODO
./README
./doc/
./doc/makedoc.rb
./doc/doc.css
./ChangeLog

Copying files to the temporary directory...OK
Striping ELF binaries and libraries...OK
Compressing man pages...OK
Building file list...OK
Building RPM package...OK
NOTE: The package will not be installed
Erasing temporary files...OK
Writing backup package...OK
Deleting temp dir...OK

**********************************************************************

Done. The new package has been saved to

/usr/src/redhat/RPMS/x86_64/rubygems-0.9.4-1.x86_64.rpm
You can install it in your system anytime using:

rpm -i rubygems-0.9.4-1.x86_64.rpm
**********************************************************************


作成された RPM をインストールします。
[root@mycentos rubygems-0.9.4]# rpm -ivh /usr/src/redhat/RPMS/x86_64/rubygems-0.9.4-1.x86_64.rpm
Preparing... ########################################### [100%]
1:rubygems ########################################### [100%]


後片付けをします。別にしなくてもいいけど。
[root@mycentos rubygems-0.9.4]# rm /usr/src/redhat/RPMS/x86_64/rubygems-0.9.4-1.x86_64.rpm
[root@mycentos rubygems-0.9.4]# cd
[root@mycenos ~]# rm -rf rubygems-0.9.4*


参考ページのおかげで、エラー無く無事終了。最後にGemsのバージョンを確認。
[root@mycentos ~]# gems -v
0.9.4


そういえば、いちどzlibがないってエラーがでたきがする・・。
/usr/local/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:4:in `require': no such file to load -- zlib (LoadError)


zlib がいるらしい。こちらのページを参考にしました。てかそのまま。
[root@mycenos ~]# yum install zlib-devel


続けて、
[root@mycenos ~]# cd ruby-1.8.6/ext/zlib
[root@mycenos zlib]# ruby extconf.rb --with-zlib-include=/usr/include --with-zlib-lib=/usr/lib
[root@mycenos zlib]# make
[root@mycenos zlib]# make install


これでいけたと思う。

追伸
もともと古いRubyやGemsがインストールされていて、古いの削除→最新をインストールとしてた場合、rubyやgemsを作成する場所を変えたら、インストール後にruby -vやgems -vを打っても、みつかんないよそんなもの~(英語)ていわれます。そのときは、一度ログアウトします。そしたら、パスが反映されました。これで半日ハマったし。