ruby-on-rails - Heroku ruby​​ 版本不匹配

标签 ruby-on-rails ruby heroku

我在使用 Heroku 和 Rails 应用程序时遇到问题。在我的 Gemfile 中,我指定了 ruby "2.1.5" 但我的应用程序崩溃并显示以下日志:

2015-04-08T20:54:15.248878+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 57371 -e production`
2015-04-08T20:54:17.365771+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/bundler-1.7.12/lib/bundler/definition.rb:380:in `validate_ruby!': Your Ruby version is 1.9.3, but your Gemfile specified 2.1.5 (Bundler::RubyVersionMismatch)
2015-04-08T20:54:17.365791+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.1.0/gems/bundler-1.7.12/lib/bundler.rb:118:in 'setup'

2015-04-08T20:54:17.365793+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.1.0/gems/bundler-1.7.12/lib/bundler/setup.rb:17:in 'top (required)'

2015-04-08T20:54:17.365795+00:00 app[web.1]:    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in 'require'

2015-04-08T20:54:17.365796+00:00 app[web.1]:    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in 'require'
2015-04-08T20:54:17.365798+00:00 app[web.1]:    from /app/config/boot.rb:3:in '<top (required)>'
2015-04-08T20:54:17.365800+00:00 app[web.1]:    from bin/rails:7:in 'require_relative'
2015-04-08T20:54:17.365802+00:00 app[web.1]:    from bin/rails:7:in <main>

2015-04-08T20:54:18.135689+00:00 heroku[web.1]: Process exited with status 1

2015-04-08T20:54:18.155346+00:00 heroku[web.1]: State changed from starting to crashed
2015-04-08T20:54:41.881395+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=....herokuapp.com request_id=1ec36521-d1ca-4ea3-b635-b79caf9b82c9 fwd="x.x.x.x" dyno= connect= service= status=503 bytes=

下面是一些奇怪的命令结果:

heroku run ruby​​ -v: ruby​​ 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux] heroku run bundle install:您的 Ruby 版本是 1.9.3,但您的 Gemfile 指定为 2.1.5 (Bundler::RubyVersionMismatch)

在我将 Gemfile 从 1.9.3 切换到 2.1.5 之前,一切都很好。任何帮助表示赞赏。此外,Heroku 似乎没有使用 rvm,所以我不知道他们是如何施展魔法的。

编辑:我已经尝试删除该应用程序并创建一个全新的 2.1.5 版本(然后是 2.2.0) 从一开始就在 Gemfile 中(尽管我从同一个 git 存储库同步了它)。

编辑 2:它确实不会在部署时崩溃,而只是在页面服务和运行 bundle(r) 时崩溃。 (到目前为止)

编辑 3: 每次我部署时,heroku 都以:

remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.1.5
remote: -----> Installing dependencies using 1.7.12
remote:        Ruby version change detected. Clearing bundler cache.
remote:        Old: ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]
remote:        New: ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
remote:        Running: bundle install --without development:test --path vendo

(旧/新版本正确)

编辑 4: 似乎 Heroku 没有正确加载环境变量(或者是吗?),因此加载和使用了错误的 ruby​​ 版本:

local$ heroku config -s | grep PATH
PATH=/app/vendor/ruby-2.1.5/bin:/app/vendor/bundle/ruby/2.1.0/bin:/bin:/usr/bin:/app/bin:/app/vendor/bundle/bin
local$ heroku run ruby -v
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
local$ heroku run bash
heroku $ echo $PATH
/app/bin:/app/vendor/bundle/bin:/app/vendor/bundle/ruby/2.1.0    /bin:/app/vendor/ruby-2.1.5/bin:/app/vendor/bundle/ruby/2.1.0    /bin:/bin:/usr/bin:/app/bin:/app/vendor/bundle/bin
heroku $ cat .profile.d/ruby.sh | grep PATH
export GEM_PATH="$HOME/vendor/bundle/ruby/2.1.0:$GEM_PATH"
export PATH="$HOME/bin:$HOME/vendor/bundle/bin:$HOME/vendor/bundle/ruby/2.1.0/bin:$PATH"

环境正在 /app/bin 中寻找 ruby 而不是 /app/vendor/ruby-2.1.5/bin。如果在 Heroku 环境中,我 export PATH 为正确的值,我可以毫无问题地运行 bundle。不幸的是,为应用程序提供服务的实例似乎不是。

我可以更改 profile.d/ruby.sh 中的 PATH 或创建 .ruby-version 文件,尽管两者都不是 nano , pico 和 vim 在 heroku 上都不可用。我该怎么办?

最佳答案

好吧,48 小时后,我在这里找到了解决方案:other SO post .

确实,我的项目中有一些遗留垃圾,即在 bin 文件夹中。这是解决问题的方法:

$ bundle config --delete bin

$ bundle exec rake rails:update:bin

所有本地。然后推送到 heroku,不要忘记包含新生成的文件。欢呼!

关于ruby-on-rails - Heroku ruby​​ 版本不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29525449/

相关文章:

ios - 通过参数将数据从 Swift 中的 iOS 发送到 Rails 应用程序

ruby-on-rails - Ruby 中的详细 URL 获取信息

Python webapp 无法在 Heroku 上正常运行?

ruby-on-rails - Heroku 错误 H10 -(应用程序崩溃)

ruby-on-rails - rails : count the click number of a link?

ruby-on-rails - Rails 3.2.8 引擎中 simple_form 的加载错误

ruby-on-rails - 创建行项目记录时将 session 用户 ID 添加到 Line_Items 表中 - Ruby on Rails

ruby-on-rails - Rails Controller 中的功能测试重定向

ruby-on-rails - Squeel 将字符串评估为连接的关键路径

ruby-on-rails - 与Redistogo一起使用时,sidekiq不会在heroku上生成sidekiq.pid文件