LoginSignup
15

More than 5 years have passed since last update.

Rubyのバージョンアップしたときに躓いたところ

Last updated at Posted at 2018-12-02

はじめに

ユアマイスターアドベントカレンダー2018 の2日目の記事です。

ちょうど1年前にRubyの開発をしていて、それからまったくアップデートしていなかったのですが、年を越す前に、負の遺産となる前に、最新バージョンにしました。
現在のバージョンはRuby 2.5.0だったので、バージョンを2.5.3にします。
そこで躓いたところを書きつつ、最後的な手順を書きました。

躓いたところ

Ruby2.5.3が出てこない

$ rbenv install -l
  ...
  2.5.0-rc1
  2.5.0
  2.5.1
  ...

rbenvでインストールできるRubyに2.5.3がない。。。
ruby-buildが古いままだったので、更新をしたらちゃんと出ました。

$ brew upgrade rbenv ruby-build

Rubyを切り替えて、終わりかと思いきやエラー

$ rbenv exec bundle exec rails s
rbenv: bundle: command not found

The `bundle' command exists in these Ruby versions:
  2.5.0

エラーに書いてある通り、Ruby 2.5.3のbundlerが入っていないからでした。
BundlerもRubyのバージョンに依存しているのかー。
bundlerをインストールし直すればOK。

$ rbenv exec gem install bundler
$ rbenv rehash

Railsテスト実行時にエラー

$ rbenv exec bundle exec rails t
Could not find nokogiri-1.8.2 in any of the sources
Run `bundle install` to install missing gems.

nokogiri-1.8.2がないらしい。
Bundlerの再インストールをすれば解決。

最終的な手順はこうなった

Homebrewを更新

$ brew update

rbenv、ruby-buildを更新

$ brew upgrade rbenv ruby-build

インストール済みのrbenvを確認

$ rbenv versions
  system
* 2.5.0 (set by /projectDir/.ruby-version)

rbenvでインストールできるRubyのバージョンを確認

$ rbenv install -l

最新のRubyをインストール

$ rbenv install 2.5.3

インストールできているか確認

$ rbenv versions
  system
* 2.5.0 (set by /projectDir/.ruby-version)
  2.5.3

インストールしたバージョンに変更

$ cd ~/projectDir
$ rbenv local 2.5.3

バージョンが切り替わっていることを確認

$ rbenv versions
  system
  2.5.0
* 2.5.3 (set by /projectDir/.ruby-version)

bundlerをインストール

$ rbenv exec gem install bundler
$ rbenv rehash

Gemを再インストール

$ rbenv exec bundle install --path vendor/bundle

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
15