centos7系はめんどくさいということで、未だに活躍中のCentOS6系。
そんなCentOS6ですが、構築するときにいつも手間取るのがrubyのインストールです。
yumでインストール可能なんですが、ruby1.8系しか入らないので何かと困ります。
今回はより新しいruby2.3.0をインストールして、gemを使えるようにするまでの手順をメモします。
Contents
構築する環境
・CentOS6.5 x86_64 を minimalDesktop でインストール
・ruby-2.3.0
・rubygems-2.5.1
1.必要なパッケージのインストール
まずrubyインストールに必要なパッケージをインストールします。
必要なのは
・開発ツール(gccなど)
・openssl-devel
・zlib-devel
です。
[root@centos6 ~]# yum -y groupinstall "Development tools" [root@centos6 ~]# yum -y install openssl-devel zlib-devel
エラーが出なければOKです。
2.rubyとgemのソースコードをダウンロード
今回はソースコードからインストールしますので、まずダウンロードします。
[root@centos6 ~]# cd /usr/local/src/ ### rubyのソース [root@centos6 src]# wget --no-check-certificate https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.gz ### gemのソース [root@centos6 src]#wget --no-check-certificate https://rubygems.org/rubygems/rubygems-2.5.1.tgz
3.rubyのコンパイル&インストール
ダウンロードしたら次はコンパイルしてインストールです。
### ソースコードを解凍 [root@centos6 src]# tar xvfz ruby-2.3.0.tar.gz [root@centos6 src]# cd ruby-2.3.0 ### コンパイル&インストール [root@centos6 ruby-2.3.0]# ./configure && make && make install 〜〜〜〜中略:以下のような出力が出ればOK〜〜〜〜 Generating RDoc documentation No newer files. Files: 0 Classes: 0 (0 undocumented) Modules: 0 (0 undocumented) Constants: 0 (0 undocumented) Attributes: 0 (0 undocumented) Methods: 0 (0 undocumented) Total: 0 (0 undocumented) 0.00% documented Elapsed: 0.0s generating x86_64-linux-fake.rb x86_64-linux-fake.rb updated ./miniruby -I./lib -I. -I.ext/common ./tool/runruby.rb --extout=.ext -- --disable-gems -r./x86_64-linux-fake ./tool/rbinstall.rb --make="make" --dest-dir="" --extout=".ext" --mflags="" --make-flags="" --data-mode=0644 --prog-mode=0755 --installed-list .installed.list --mantype="doc" --install=all --rdoc-output=".ext/rdoc" installing binary commands: /usr/local/bin installing base libraries: /usr/local/lib installing arch files: /usr/local/lib/ruby/2.3.0/x86_64-linux installing pkgconfig data: /usr/local/lib/pkgconfig installing command scripts: /usr/local/bin installing library scripts: /usr/local/lib/ruby/2.3.0 installing common headers: /usr/local/include/ruby-2.3.0 installing manpages: /usr/local/share/man/man1 installing extension objects: /usr/local/lib/ruby/2.3.0/x86_64-linux installing extension objects: /usr/local/lib/ruby/site_ruby/2.3.0/x86_64-linux installing extension objects: /usr/local/lib/ruby/vendor_ruby/2.3.0/x86_64-linux installing extension headers: /usr/local/include/ruby-2.3.0/x86_64-linux installing extension scripts: /usr/local/lib/ruby/2.3.0 installing extension scripts: /usr/local/lib/ruby/site_ruby/2.3.0 installing extension scripts: /usr/local/lib/ruby/vendor_ruby/2.3.0 installing extension headers: /usr/local/include/ruby-2.3.0/ruby installing default gems: /usr/local/lib/ruby/gems/2.3.0 (build_info, cache, doc, extensions, gems, specifications) bigdecimal 1.2.8 io-console 0.4.5 json 1.8.3 psych 2.0.17 rdoc 4.2.1 installing bundle gems: /usr/local/lib/ruby/gems/2.3.0 (build_info, cache, doc, extensions, gems, specifications) did_you_mean 1.0.0 minitest 5.8.3 test-unit 3.1.5 power_assert 0.2.6 rake 10.4.2 net-telnet 0.1.1 installing rdoc: /usr/local/share/ri/2.3.0/system installing capi-docs: /usr/local/share/doc/ruby
私の環境ではエラーは出ませんでした。
4.gemのインストール
最後にgemをインストールします。
[root@centos6 ruby-2.3.0]# cd ../ [root@centos6 src]# tar xvfz rubygems-2.5.1.tgz [root@centos6 src]# cd rubygems-2.5.1 [root@centos6 rubygems-2.5.1]# ruby setup.rb * RubyGems handles invalid config files better. Pull request #1367 by Agis Anastasopoulos. ------------------------------------------------------------------------------ RubyGems installed the following executables: /usr/local/bin/gem Ruby Interactive (ri) documentation was installed. ri is kind of like man pages for ruby libraries. You may access it like this: ri Classname ri Classname.class_method ri Classname#instance_method If you do not wish to install this documentation in the future, use the --no-document flag, or set it as the default in your ~/.gemrc file. See 'gem help env' for details.
このように表示されればOKです。
最後に正しくインストールされるか確認します。
[root@centos6 rubygems-2.5.1]# gem update --system Latest version currently installed. Aborting.
上記のように表示されればOKです。
うまくいかない場合、ここでエラーが出ますので問題を取り除き、再度インストールしましょう。