LoginSignup
10
6

More than 5 years have passed since last update.

Your Ruby version is 2.5.3, but your Gemfile specified 2.5.1

Posted at

TL;DR

とある日の朝、RORのプロジェクトを開発環境で立ち上げようとしたところ、こんなエラーが吐かれた。そのデバッグ記録です。

Debug

いつものように開発環境のRORプロジェクトをgem foremanで立ち上げようとした。

$ ~/project_dir bundle exec foreman start -f Procfile.dev

ところがこんなエラーが、、

#=> Your Ruby version is 2.5.3, but your Gemfile specified 2.5.1

なるほど、参照先のruby versionとGemfileで設定しているruby versionが違うらしい。素直にGemfileのruby versionを参照先と合わせて2.5.3に設定しよう。
設定した。もう一回起動。

$ ~/project_dir bundle exec foreman start -f Procfile.dev

しかし今度は、

#=> 11:18:47 frontend.1 | exited with code 1

webpacl-dev-serverが異常終了した。なんでだ?webpack-dev-serverだけ実行してみる。

$ ~/project_dir ./bin/webpack-dev-server
#=> Your Ruby version is 2.5.1, but your Gemfile specified 2.5.3

今度は、Gemfileに設定したruby 2.5.3がだめなのか笑
bundlerとwebpack-dev-serverでrubyの参照先が違うんだろうな。

ちなみに、

$ rbenv versions
    system
    2.4.1
    2.5.0
  * 2.5.1

$ ruby -v
  ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]

All the 2.5.1笑

一体いつどこに入れた2.5.3だろう?そういえば昨日ハイボールを飲みながらdjangoをいじってたときになんか2.5.3っていう数字を見た気も、、、まぁどうでもいいか。

Debug再開。 bundler はどこだ?

$ which bundler
#=> /usr/local/bin/bundler

中身を見てみる。

$ cat /usr/local/bin/bundle

#!/usr/local/opt/ruby/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'bundler' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0.a"
if ARGV.first
  str = ARGV.first
  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
    version = $1
    ARGV.shift
  end
end
if Gem.respond_to?(:activate_bin_path)
load Gem.activate_bin_path('bundler', 'bundle', version)
else
gem "bundler", version
load Gem.bin_path("bundler", "bundle", version)
end

なるほどshebangによると、参照先は #!/usr/local/opt/ruby/bin/ruby か。
rbenvでrubyのversionは管理してるし、参照先を直接変えちゃおうか。うまくいくだろう。

$ sudo vim /usr/local/bin/bundler

あなたの環境でのpathを設定してください。

#!/usr/local/.rbenv/shims/ruby #変更!
#
# This file was generated by RubyGems.
#
# The application 'bundler' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0.a"
if ARGV.first
  str = ARGV.first
  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
    version = $1
    ARGV.shift
  end
end
if Gem.respond_to?(:activate_bin_path)
load Gem.activate_bin_path('bundler', 'bundle', version)
else
gem "bundler", version
load Gem.bin_path("bundler", "bundle", version)
end

ではもう一度、

$ ~/project_dir bundle exec foreman start -f Procfile.dev
11:34:13 web.1      | started with pid 19518
11:34:13 frontend.1 | started with pid 19519
11:34:17 frontend.1 | Project is running at http://localhost:3035/
11:34:17 frontend.1 | webpack output is served from /packs/
11:34:17 frontend.1 | Content not from webpack is served from ***
11:34:20 frontend.1 | No parser and no filepath given, using 'babylon' the parser now but this will throw an error in the future. Please specify a parser or a filepath so one can be inferred.
11:34:20 frontend.1 | No parser and no filepath given, using 'babylon' the parser now but this will throw an error in the future. Please specify a parser or a filepath so one can be inferred.
11:34:25 web.1      | => Booting Puma
11:34:25 web.1      | => Rails 5.2.1 application starting in development 
11:34:25 web.1      | => Run `rails server -h` for more startup options
11:34:27 web.1      | Puma starting in single mode...
11:34:27 web.1      | * Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
11:34:27 web.1      | * Min threads: 5, max threads: 5
11:34:27 web.1      | * Environment: development
11:34:27 web.1      | * Listening on tcp://localhost:5000
11:34:27 web.1      | Use Ctrl-C to stop

お、動いた!

まとめ

お使いのrubyの参照先を確認して、各プロセスを担う方たちに適切な参照先を割り当てるようにdebugしましょう、といった感じでした:sake:

10
6
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
10
6