LoginSignup
62
54

More than 5 years have passed since last update.

rbenv-updateを使ってRubyのバージョンを上げたついでにRailsをインストールした(CentOS)

Last updated at Posted at 2015-02-17

rbenv plugin の rbenv-update を使用してRubyのバージョンを上げました。環境はMacにあるVagrantのCentOSです。

きっかけ

以前rbenvでrubyのバージョンを上げた流れを投稿した記事へ、rbenv-updateを使うとrbenvのupdateは楽ですよとコメントをいただいたので使ってみました。

rbenvのバージョンなどはrbenvを再インストールしてRubyのバージョンを上げた(CentOS)に書いてあるバージョンと同じです。

rbenv-updateをインストールする

rbenvのpluguinをインストールします。
手順は https://github.com/rkh/rbenv-update ある通り3つのコマンドを順番に実行します。

rbenv-updateをインストール
[ -z "$RBENV_ROOT" ] && export RBENV_ROOT="$HOME/.rbenv"
mkdir -p "$RBENV_ROOT/plugins"
git clone https://github.com/rkh/rbenv-update.git "$RBENV_ROOT/plugins/rbenv-update"

これでrbenv-updateがインストールされました。

rbenvをupdateする

rbenv-updateをインストールしたのでrbenv updateでrbenvをアップデートします。

rbenvをアップデート
rbenv update
updating rbenv
 |  From https://github.com/sstephenson/rbenv
 |  13a474c..1a7f49d  master     -> origin/master
略

rbenvのバージョンを確認します。

rbenvのバージョンを確認
rbenv --version
rbenv 0.4.0-131-g1a7f49d

rbenvがアップデートされてバージョンがあがりました。

バージョンを指定してRubyをインストールする

ruby-2.2.0をインストールします。

バージョン指定してRubyをインストール
rbenv install -v 2.2.0

略

make[3]: ディレクトリ `/tmp/ruby-build.20150217115516.6099/ruby-2.2.0/ext/fiddle/libffi-3.2.1' から出ます
linking shared-object fiddle.so
/usr/bin/ld: ./libffi-3.2.1/.libs/libffi.a(raw_api.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
./libffi-3.2.1/.libs/libffi.a: could not read symbols: Bad value
collect2: ld はステータス 1 で終了しました
make[2]: *** [../../.ext/x86_64-linux/fiddle.so] エラー 1

略

エラーがでてlibffiが無いと言われました。

libffi-develをインストール

先にlibffi-develをインストールします。

libffi-develをインストール
sudo yum -y install libffi-devel

再度Rubyをインストール

再度Rubyのインストールを試します。

バージョン指定してRubyをインストール
rbenv install -v 2.2.0

今度は成功しました。
インストールされているRubyのバージョンを確認します。

rbenvでRubyのどのバージョンがインストールされているかを確認
rbenv versions
  system
* 2.1.2 (set by /home/vagrant/.rbenv/version)
  2.2.0

ちゃんと2.2.0が入っています。以前は~/.ruby-versionでバージョン指定をしていたと思ったのですが、いつの間にか~/.rbenv/versionでRubyのバージョンが指定されているようです。

~/.rbenv/versionを書き換える
vi ~/.rbenv/version
2.2.0

rehashします。

rbenvをrehash
rbenv rehash

rbenvがどのRubyのversionを使用しているか確認します。

rbenvがRubyのどのバージョンを使用しているか確認
rbenv versions
  system
  2.1.2
* 2.2.0 (set by /home/vagrant/.rbenv/version)

rbenvではRubyが2.2.0に変更されています。

Rubyのバージョンを確認

Rubyのversionを確認します。

Rubyのバージョンを確認
ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]

目的どおりruby2.2.0になりました☆(ゝω・)vキャピ

Railsをインストール

Rubyが上がったのでついでにRailsをインストールします。

railsをインストール
gem install rails
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

    /home/vagrant/.rbenv/versions/2.2.0/bin/ruby -r ./siteconf20150217-11667-1sfqxua.rb extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
checking for gzdopen() in -lz... yes
checking for iconv... yes
************************************************************************
IMPORTANT NOTICE:

Building Nokogiri with a packaged version of libxml2-2.9.2
with the following patches applied:
    - 0001-Revert-Missing-initialization-for-the-catalog-module.patch
    - 0002-Fix-missing-entities-after-CVE-2014-3660-fix.patch

Team Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows:

    gem install nokogiri -- --use-system-libraries
        [--with-xml2-config=/path/to/xml2-config]
        [--with-xslt-config=/path/to/xslt-config]

If you are using Bundler, tell it to use the option:

    bundle config build.nokogiri --use-system-libraries
    bundle install

Note, however, that nokogiri is not fully compatible with arbitrary
versions of libxml2 provided by OS/package vendors.
************************************************************************
Extracting libxml2-2.9.2.tar.gz into tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.9.2... OK
Running patch with /home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/nokogiri-1.6.6.2/ports/patches/libxml2/0001-Revert-Missing-initialization-for-the-catalog-module.patch...
Running 'patch' for libxml2 2.9.2... ERROR, review '/home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/nokogiri-1.6.6.2/ext/nokogiri/tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.9.2/patch.log' to see what happened.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

(´゚д゚`)アチャーこれnokogiriを入れろってやつです。

nokogiriをインストール

エラーメッセージにあるようにnokogiriをインストールします。

nokogiriをインストール
gem install nokogiri -- --use-system-libraries

nokogiriがインストールされました。

再度 Railsをインストール

もういちどrailsのインストールを試みます。

railsをインストール
gem install rails

nokogiriを入れたため今度はエラーが出ませんでした。

Railsのバージョンを確認

Railsのバージョンを確認します。

railsのバージョンを確認
rails -v
Rails 4.2.0

ちゃんとインストールされたみたいです(☝ ՞ਊ ՞)

参考

62
54
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
62
54