2007年8月6日月曜日

CentOS という Linux へ Ruby をインストール

Rubyの最新バージョンをインストール

Ruby on Railsをインストールするためにまず、Rubyの最新バージョンをインストール。
Ruby on Rails が求める Ruby のバージョンは 1.8.2 以上です。(※現在2007/08)
もともと、1.8.1がインストールされていたので、削除して、1.8.6をインストールします。

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

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

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

■Rubyの確認

rubyがあるか確認
[root@mycentos ~]# ruby -v


1.8.1がインストールされてます。
[root@mycentos ~]# ruby 1.8.1 (2003-03-13 patchlevel 0) [x86_64-linux]


インストールされてなければ、以下のように表示される。
[root@mycentos ~]# rubyなんてないよ(英語で)


参考ページにしたがって、ruby1.8.1をアンインストールする。
[root@mycentos ~]# yum remove ruby-libs


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

2007年8月6日現在で最新バージョンはruby1.8.6です。
最新版は Ruby の公式ページで確認できます。

今回はwgetコマンドで最新バージョンをダウンロード
[root@mycentos ~]# wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6.tar.gz


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


Ruby をビルドします。checkinstall を使って RPM として管理するので、「--prefix=/usr/local」をつけてインストール先を /usr/local にします。
理解してません。参考ページのいいなりです。
[root@mycentos ruby-1.8.6]# ./configure --prefix=/usr/local
     ・
     ・
[root@mycentos ruby-1.8.6]# make
     ・
     ・


checkinstall を使って RPM 化します。
Ruby は「make install」でインストールするとインストールしたファイルを参照しながらインストール処理を続けるので、そのような場合は 「--fstrans=no」オプションをつける必要があります。
理解してません。参考ページのいいなりです。
[root@mycentos ruby-1.8.6]# checkinstall --fstrans=no


以下の状態で止まります。デフォルトのパッケージドキュメントを作っていいかと聞かれます。作ってもいいのでそのまま Enter (デフォルトで Yes なので)を押します。
checkinstall 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]:


続いてパッケージタイプを聞かれます。RPM なので r を入力します。
Preparing package documentation...OK
Please choose the packaging method you want to use.Slackware [S], RPM [R] or Debian [D]?


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


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


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

Installing with make install...

========================= Installation results ===========================./miniruby ./instruby.rb --dest-dir="" --extout=".ext" --make="make" --mflags="" --make-flags="" --installed-list .installed.list --mantype="doc"
installing binary commands
installing command scripts
installing library scripts
installing headers
installing manpages
installing extension objects
installing extension scripts

======================== Installation successful ==========================
Copying documentation directory...
./
./README.ja
./README.EXT.ja
./COPYING
./COPYING.ja
    ・
    ・
Building RPM package...OK
NOTE: The package will not be installed
Erasing temporary files...OK
Deleting doc-pak directory...OK
Writing backup package...OK
Deleting temp dir...OK

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

Done. The new package has been saved to

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

rpm -i ruby-1.8.6-1.x86_64.rpm
**********************************************************************


作成された RPM をインストールします。【rpm -i ruby-1.8.6-1.x86_64.rpm】て書かれてるけど、参考ページにしたがって
[root@mycentos ruby-1.8.6]# rpm -Uvh /usr/src/redhat/RPMS/x86_64/ruby-1.8.6-1.x86_64.rpm
Preparing... ########################################### [100%]
1:ruby ########################################### [100%]


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


参考ページのおかげで、エラー無く無事終了。最後にRubyのバージョンを確認。
[root@mycentos ~]# ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [x86_64-linux]

0 件のコメント: