他力本願でruby2.2.2のrpm化をして挫折した記録

はじめに

rubyをrpm化する必要があったので、調べてみました。
rpmbuild自体をしたことがなかったのですが、他のblog記事を参考にしながら行っています。加えてspecファイルを提供して頂いている方がいたのでそちらも利用する他力本願仕様です。

各種ファイルのダウンロード

今回ダウンロードするファイルはruby本体のファイルとspecファイルです

RPMを作成する前の準備

  1. ディレクトリの作成

buildに必要なディレクトリを作成します。

$ mkdir rpmbuild # 作業用にほっただけなので任意の名前で
$ cd rpmbuild
$ mkdir BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
$ mkdir -p RPMS/{athlon,i386,i486,i586,i686,noarch,x86_64}
  1. 必要ファイルのダウンロード
$ cd SPECS
$ wget http://www.torutk.com/attachments/download/354/ruby222.spec
$ cd ../SOURCES
$ wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz
  1. specファイル

インストールする場所をかえたかったので — prefixを追加しました。

--- C:UserskatsumataDownloadsruby222.spec
+++ %define rubyver 2.2.2
@@ -36,6 +36,7 @@
export CFLAGS="$RPM_OPT_FLAGS -Wall -fno-strict-aliasing"

%configure
+ --prefix=/usr/local/rubys/
--enable-shared
--disable-rpath
--without-X11

RPMの作成

$ pwd
/home/username/rpmbuild # rpmbuildの中に居ます
# ビルドします ※rootで作業しないほうがいいらしいです
$ rpmbuild -bb SPECS/ruby222.spec

エラーがでました

error: Installed (but unpackaged) file(s) found:

調べてみたところ、下記のサイトに記載がありました。
参考: http://wiliki.zukeran.org/index.cgi?rpmbuild%a4%b9%a4%eb%a4%c8%20error%3a%20Installed%20%28but%20unpackaged%29%20file%28s%29%20found%3a%a4%ac%bd%d0%a4%eb#H-aaenzu8px

「パッケージには含まれてるけど、インストール対象になってないというエラー」はSPECファイルの %files に記載する必要が有るようです。修正します。
元のファイルとの差分は以下のとおりです。

--- C:UserskatsumataDownloadsruby222.spec
+++ %define rubyver 2.2.2
@@ -36,6 +36,7 @@
export CFLAGS="$RPM_OPT_FLAGS -Wall -fno-strict-aliasing"

%configure
+ --prefix=/usr/local/rubys/
--enable-shared
--disable-rpath
--without-X11
@@ -56,6 +57,7 @@
rm -rf $RPM_BUILD_ROOT

%files
+/usr/local/rubys/share/ri/2.2.0/system/*
%defattr(-, root, root)
%{_bindir}
%{_includedir}

rpmファイルの完成(失敗する)

もう一度 rpmbuildを行うと RPMS/ の 環境名のディレクトリに 「ruby-2.2.2–1.el7.centos.x86_64.rpm」というファイルができていました。

こちらを
$ sudo yum localinstall ruby-2.2.2–1.el7.centos.x86_64.rpm 
でインストールしたところobsolute関連でエラー(既存でインストールされているrubyとバッティングして削除できない?)が起こる。当初から別環境で共存することを目指しているのでこの方法はよくなさそう。

対策

SPECファイルを編集してみました。さっきのファイル修正からの差分ですrubyをruby22にしただけです。

--- C:UserskatsumataDownloadsruby222.spec
+++ %define rubyver 2.2.2
@@ -1,6 +1,6 @@
%define rubyver 2.2.2


-Name: ruby
+Name: ruby22
Version: %{rubyver}
Release: 1%{?dist}
License: Ruby License/GPL - see COPYING
@@ -11,17 +11,17 @@
Source0: ftp://ftp.ruby-lang.org/pub/ruby/ruby-%{rubyver}.tar.bz2
Summary: An interpreter of object-oriented scripting language
Group: Development/Languages
-Provides: ruby(abi) = 2.2
-Provides: ruby-irb
-Provides: ruby-rdoc
-Provides: ruby-libs
-Provides: ruby-devel
-Provides: rubygems
-Obsoletes: ruby-libs
-Obsoletes: ruby-irb
-Obsoletes: ruby-rdoc
-Obsoletes: ruby-devel
-Obsoletes: rubygems
+Provides: ruby22(abi) = 2.2
+Provides: ruby22-irb
+Provides: ruby22-rdoc
+Provides: ruby22-libs
+Provides: ruby22-devel
+Provides: rubygems22
+Obsoletes: ruby22-libs
+Obsoletes: ruby22-irb
+Obsoletes: ruby22-rdoc
+Obsoletes: ruby22-devel
+Obsoletes: rubygems22

再度rpmbuild

※ sudo yum localeinstall の際にSERVERに db4関係 yumでインストールできなかったので db4-devel, db4を外しています

$ sudo yum localinstall ruby22-2.2.2-1.el7.centos.x86_64.rpm
[sudo] password for :
Loaded plugins: fastestmirror
Examining ruby22-2.2.2-1.el7.centos.x86_64.rpm: ruby22-2.2.2-1.el7.centos.x86_64
Marking ruby22-2.2.2-1.el7.centos.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package ruby22.x86_64 0:2.2.2-1.el7.centos will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===================================================================================================================
Package Arch Version Repository Size
===================================================================================================================
Installing:
ruby22 x86_64 2.2.2-1.el7.centos /ruby22-2.2.2-1.el7.centos.x86_64 35 M
Transaction Summary
===================================================================================================================
Install 1 Package
Total size: 35 M
Installed size: 35 M
Transaction check error:
file /usr/bin from install of ruby22-2.2.2-1.el7.centos.x86_64 conflicts with file from package filesystem-3.2-18.el7.x86_64
file /usr/lib64 from install of ruby22-2.2.2-1.el7.centos.x86_64 conflicts with file from package filesystem-3.2-18.el7.x86_64
file /usr/bin/irb from install of ruby22-2.2.2-1.el7.centos.x86_64 conflicts with file from package ruby-irb-2.0.0.598-24.el7.noarch
file /usr/bin/erb from install of ruby22-2.2.2-1.el7.centos.x86_64 conflicts with file from package ruby-2.0.0.598-24.el7.x86_64
file /usr/bin/ruby from install of ruby22-2.2.2-1.el7.centos.x86_64 conflicts with file from package ruby-2.0.0.598-24.el7.x86_64
file /usr/share/man/man1/ruby.1.gz from install of ruby22-2.2.2-1.el7.centos.x86_64 conflicts with file from package ruby-2.0.0.598-24.el7.x86_64
file /usr/lib64/libruby.so from install of ruby22-2.2.2-1.el7.centos.x86_64 conflicts with file from package ruby-devel-2.0.0.598-24.el7.x86_64
エラーがでてまして、やっぱりruby2.0とバッティングしてしまうので一旦時間がかかり過ぎそうということで今回はここまでと。。。