Nicolas Mattia Nicolas Mattia - 18 days ago 5
Ruby Question

Heroku ruby versions mismatch

I am having a problem with Heroku and a Rails app. In my Gemfile I specify

ruby "2.1.5"
but my app crashes with the following log:

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=


and here are a few weird results of commands:

heroku run ruby -v: ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]

heroku run bundle install: Your Ruby version is 1.9.3, but your Gemfile specified 2.1.5 (Bundler::RubyVersionMismatch)


Everything was fine before I switched my Gemfile from 1.9.3 to 2.1.5. Any help is appreciated. Also, it does not look like Heroku is using rvm, so I have no idea how they do their magic.

EDIT: I already tried deleting the app and creating a fresh, new one with version
2.1.5
(and then later
2.2.0
) in the Gemfile from the beginning (though I synced it from the same git repo).

EDIT 2: It does not actually crash on deploy, rather only on page serving, and when running
bundle(r)
. (so far)

EDIT 3: Every time I deploy, heroku starts with:

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


(with correct versions for old/new)

EDIT 4: it seems that Heroku is not loading the environment variables correctly (or is it?), and so the wrong ruby version is loaded and used:

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"


The environment is looking for
ruby
in
/app/bin
instead of
/app/vendor/ruby-2.1.5/bin
. If, in the Heroku environment, I
export PATH
to the correct values, I can run
bundle
with no problem. Unfortunately, it seems that the instance serving the app is not.

I could either change the
PATH
in
profile.d/ruby.sh
or create the
.ruby-version
file, though neither nano, nor pico nor vim are available on heroku. How am I supposed to?

Answer

Alright, 48 hours later, I found the solution here : other SO post.

Indeed, there was some leftover crap in my project, namely in the bin folder. Here's what solved it:

$ bundle config --delete bin

$ bundle exec rake rails:update:bin

all localy. Then push to heroku, without forgetting to include the newly generated files. Hurray!

Comments