hene

hene.dev

Rails と Ruby のアップデート

Rails と Ruby のアップデート

アップデート内容

  • Ruby: 2.5.0 -> 2.6.1
  • Rails: 5.1.4 -> 5.2.2

Ruby のアップデート

rbenv と ruby-build のアップデート

$ brew upgrade rbenv ruby-build

rbenv

Ruby のバージョン管理を行うツール。

ruby-build

rbenv のプラグイン。 rbenv install コマンドが使えるようになる。

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

$ rbenv install
Available versions:
  1.8.5-p52
  ...
  2.6.0
  2.6.1
  2.7.0-dev
  jruby-1.5.6
  jruby-1.6.3
  jruby-1.6.4
  ...

2.6.1 が出ない。

一応インストール

$ rbenv install 2.6.1
ruby-build: definition not found: 2.6.1

See all available versions with `rbenv install --list'.

If the version you need is missing, try upgrading ruby-build:

  cd /Users/xxxxxx/.rbenv/plugins/ruby-build && git pull && cd -

だめだった。

ruby-build をアップグレードしてと言われたので、やってみる。

$ cd /Users/xxxxxx/.rbenv/plugins/ruby-build && git pull && cd -
remote: Enumerating objects: 540, done.
remote: Counting objects: 100% (540/540), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 810 (delta 534), reused 539 (delta 534), pack-reused 270
Receiving objects: 100% (810/810), 216.66 KiB | 469.00 KiB/s, done.
Resolving deltas: 100% (619/619), completed with 182 local objects.
From https://github.com/sstephenson/ruby-build
   d7fa3ad..0e33b11  master     -> origin/master
 * [new tag]         v20180601  -> v20180601

 略

Updating d7fa3ad..0e33b11
Fast-forward
 .travis.yml                             |  3 +++

 略

 257 files changed, 479 insertions(+), 274 deletions(-)
 create mode 100755 script/update-rbx-defs

 略

~/project/project_name

ruby-2.6.1 のインストール

$ rbenv install 2.6.1
ruby-build: use openssl from homebrew
Downloading ruby-2.6.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.1.tar.bz2
Installing ruby-2.6.1...
ruby-build: use readline from homebrew
Installed ruby-2.6.1 to /Users/xxxxxx/.rbenv/versions/2.6.1

インストールされているか確認

$ rbenv versions
  system
  2.3.4
  2.4.1
* 2.5.0 (set by /Users/xxxxxx/project/project_name/.ruby-version)
  2.5.1
  2.6.0-preview1
  2.6.1

.ruby-version 変更

.ruby-version のファイルで、Ruby のバージョンを管理していたので変更。

$ rbenv local 2.6.1

自動的に .ruby-version の中身が変更される。

# .ruby-version

-2.5.0
+2.6.1

ruby のバージョン確認

$ ruby -v
ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin17]
$ rbenv versions
  system
  2.3.4
  2.4.1
  2.5.0
  2.5.1
  2.6.0-preview1
* 2.6.1 (set by /Users/xxxxxx/project/project_name/.ruby-version)

bundle exec rails c

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

The `rails' command exists in these Ruby versions:
  2.3.4
  2.4.1
  2.5.0
  2.5.1

できないので、Rails もアップデートする。

Rails のアップデート

Gemfile を変更。

# Gemfile
 ...
 gem 'puma', '~> 3.7'
-gem 'rails', '~> 5.1.4'
+gem 'rails', '~> 5.2.2'
 gem 'redis', '~> 3.0'
 gem 'redis-rails'
 ...

bundle update --conservative rails

--conservative をつけることで他の gem のアップデートを抑制することができます。

$ bundle update --conservative rails
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching https://github.com/rails/webpacker.git
Fetching https://github.com/stympy/faker.git
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Bundler could not find compatible versions for gem "activemodel":
  In snapshot (Gemfile.lock):
    activemodel (= 5.1.4)

  In Gemfile:
    counter_culture was resolved to 1.9.1, which depends on
      activerecord (>= 3.0.0) was resolved to 5.1.4, which depends on
        activemodel (= 5.1.4)

    rails (~> 5.2.2) was resolved to 5.2.2, which depends on
      activemodel (= 5.2.2)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

activemodelupdate する。

$ bundle update --conservative rails activemodel
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Bundler could not find compatible versions for gem "actionpack":
  In snapshot (Gemfile.lock):
    actionpack (= 5.1.4)

  In Gemfile:
    rails (~> 5.2.2) was resolved to 5.2.2, which depends on
      actionpack (= 5.2.2)

    web-console (>= 3.3.0) was resolved to 3.5.1, which depends on
      railties (>= 5.0) was resolved to 5.1.4, which depends on
        actionpack (= 5.1.4)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

上のように、update しないといけないものを追加していく。

$ bundle update --conservative rails activerecord actionpack activemodel activesupport actionview railties dotenv-rails dotenv
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies.....
Fetching rake 12.3.0
Installing rake 12.3.0

略

Bundle updated!
Post-install message from yard:
--------------------------------------------------------------------------------
As of YARD v0.9.2:

RubyGems "--document=yri,yard" hooks are now supported. You can auto-configure
YARD to automatically build the yri index for installed gems by typing:

    $ yard config --gem-install-yri

See `yard config --help` for more information on RubyGems install hooks.

You can also add the following to your .gemspec to have YARD document your gem
on install:

    spec.metadata["yard.run"] = "yri" # use "yard" to build full HTML docs.

--------------------------------------------------------------------------------

問題ないか確認

  • 検証環境で問題ないか
  • テストが落ちてないか
  • 本番環境リリース後に問題ないか

参考

関連記事