首页 > 解决方案 > 没有 rvm 或 rbenv 的 ruby​​ 升级后 Ruby 版本不匹配

问题描述

我正在使用 bluepill 管理独角兽,并且在 ruby​​ 升级后独角兽启动失败并出现以下错误:

/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/definition.rb:495:in `validate_ruby!': Your Ruby version is 2.1.4, but your Gemfile specified 2.3.7 (Bundler::RubyVersionMismatch)
    from /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/definition.rb:470:in `validate_runtime!'
    from /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler.rb:101:in `setup'
    from /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/setup.rb:20:in `<top (required)>'
    from /usr/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /usr/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
E, [2019-02-20T10:42:13.897013 #10437] ERROR -- : reaped #<Process::Status: pid 12149 exit 1> exec()-ed

奇怪的是它只有在通过 capistrano 部署调用时才会失败。如果我在服务器上手动运行它,它运行良好。我尝试了各种各样的东西,但似乎没有任何效果。

提前致谢。

运行独角兽的 Bluepill 配置:

Bluepill.application(APPLICATION_NAME) do |application|
  application.working_dir = "/var/apps/APPLICATION_NAME/current"

  process "unicorn" do
    start_command    "/usr/local/bin/bundle exec unicorn -c config/unicorn.rb -E qa -D"
    environment      ({

      "RAILS_ENV"  => "qa",
      "RACK_ENV"   => "qa"
    })
    pid_file         "/var/apps/APPLICATION/shared/pids/unicorn.pid"
    cache_actual_pid false
    stop_command     "kill -QUIT {{PID}}"
    restart_command  "kill -USR2 {{PID}}"

    start_grace_time   60.seconds
    stop_grace_time    20.seconds
    restart_grace_time 13.seconds

    checks :flapping, :times => 2, :within => 30.seconds, :retry_in => 7.seconds

    monitor_children do
      stop_command "kill -QUIT {{PID}}"

      checks :mem_usage, :every => 10.seconds, :below => 500.megabytes, :times => [3,4], :fires => :stop
      checks :cpu_usage, :every => 10.seconds, :below => 20, :times => [3,4], :fires => :stop
    end
  end
end

标签: rubycapistranounicornbluepillruby-upgrade

解决方案


The error is pretty clear: Your Ruby version is 2.1.4, but your Gemfile specified 2.3.7

Did you check the ruby version in your Gemfile? It should match the ruby version you're using and you'll likely need to run

bundle update

and

bundle install

推荐阅读