Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Push to Rails Production Gives Response Your Ruby version is 1.9.3, but your Gemfile specified 2.2.2 When Ruby Version is 2.2.2

I have seen this error all over the place, but none of the solutions I have found have helped to fix the issue. I am developing a rails app locally on a Mac and have set up a droplet on DigitalOcean to push the app to. My droplet is running Ubuntu 14 and i am deploying using a Git post-receive hook. This is the hook:

#!/bin/bash

GIT_DIR=/home/xxx/yyy_production
WORK_TREE=/home/xxx/yyy
export XXX_DATABASE_USER='xxx'
export XXX_DATABASE_PASSWORD='12345'

export RAILS_ENV=production
. ~/.bashrc

while read oldrev newrev ref
do
    if [[ $ref =~ .*/master$ ]];
    then
        echo "Master ref received.  Deploying master branch to production..."
        mkdir -p $WORK_TREE
        git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f
        mkdir -p $WORK_TREE/shared/pids $WORK_TREE/shared/sockets $WORK_TREE/shared/log

        # start deploy tasks
        cd $WORK_TREE
        bundle install
        rake db:create
        rake db:migrate
        rake assets:precompile
        sudo restart puma-manager
        sudo service nginx restart
        # end deploy tasks
        echo "Git hooks deploy complete"
    else
        echo "Ref $ref successfully received.  Doing nothing: only the master branch may be deployed on this server."
    fi
done

This is the output I get when I push:

Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 444 bytes | 0 bytes/s, done.
Total 5 (delta 4), reused 0 (delta 0)
remote: Master ref received.  Deploying master branch to production...
remote: Your Ruby version is 1.9.3, but your Gemfile specified 2.2.2
remote: rake aborted!
remote: Bundler::RubyVersionMismatch: Your Ruby version is 1.9.3, but your Gemfile specified 2.2.2

I don't understand this at all, as I have installed ruby 2.2.2 and selected it using RVM. When I log on to the Ubuntu machine using ssh, I don't get any errors at all running bundler. Yet this is what it does when I run using my hook. I've been fighting with this for several days. Any help is greatly appreciated.

Just some additional info:

ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]

rvm info

ruby-2.2.2:

  system:
    uname:       "Linux mgots-app-01 3.13.0-68-generic #111-Ubuntu SMP Fri Nov 6 18:17:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux"
    system:      "ubuntu/14.04/x86_64"
    bash:        "/bin/bash => GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)"
    zsh:         " => not installed"

  rvm:
    version:      "rvm 1.26.11 (master) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]"
    updated:      "21 hours 6 minutes 30 seconds ago"
    path:         "/usr/share/rvm"

  ruby:
    interpreter:  "ruby"
    version:      "2.2.2p95"
    date:         "2015-04-13"
    platform:     "x86_64-linux"
    patchlevel:   "2015-04-13 revision 50295"
    full_version: "ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]"

  homes:
    gem:          "/home/xxx/.rvm/gems/ruby-2.2.2"
    ruby:         "/usr/share/rvm/rubies/ruby-2.2.2"

  binaries:
    ruby:         "/usr/share/rvm/rubies/ruby-2.2.2/bin/ruby"
    irb:          "/usr/share/rvm/rubies/ruby-2.2.2/bin/irb"
    gem:          "/usr/share/rvm/rubies/ruby-2.2.2/bin/gem"
    rake:         "/usr/share/rvm/rubies/ruby-2.2.2/bin/rake"

  environment:
    PATH:         "/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2@global/bin:/usr/share/rvm/rubies/ruby-2.2.2/bin:/usr/share/rvm/bin:/home/carl/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2@global/bin:/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2@global/bin:/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2@global/bin:/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2@global/bin:/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2@global/bin:/home/xxx/.rbenv/plugins/ruby-build/bin:/home/xxx/.rbenv/shims:/home/xxx/.rbenv/bin:/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2@global/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
    GEM_HOME:     "/home/xxx/.rvm/gems/ruby-2.2.2"
    GEM_PATH:     "/home/xxx/.rvm/gems/ruby-2.2.2:/home/xxx/.rvm/gems/ruby-2.2.2@global"
    MY_RUBY_HOME: "/usr/share/rvm/rubies/ruby-2.2.2"
    IRBRC:        "/usr/share/rvm/rubies/ruby-2.2.2/.irbrc"
    RUBYOPT:      ""
    gemset:       ""

EDIT: posting further data per request

Gemfile

source 'https://rubygems.org'
ruby "2.2.2"

gem 'rails',                                '4.2.2'
gem 'pg'
gem 'bootstrap-sass',               '3.3.5.1'
gem 'sass-rails',                   '~> 5.0'
gem 'uglifier',                         '>= 1.3.0'
gem 'coffee-rails',                 '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder',                         '~> 2.0'
gem 'font-awesome-rails'
gem 'sdoc',                                 '~> 0.4.0', group: :doc
gem 'bcrypt', '~> 3.1.7'
gem 'geocoder',                         '1.2.12'

group :development, :test do
  gem 'byebug'
  gem 'web-console',                    '~> 2.0'
    gem 'spring'
end

group :production do
  gem 'puma'
  gem 'therubyracer', platforms: :ruby
end

rvm list

rvm rubies

 * ruby-2.2.1 [ x86_64 ]
=> ruby-2.2.2 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

~/.bashrc

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
if [[ -n "$PS1" ]]; then
  # Some code here... e.g.
  export HISTCONTROL=ignoreboth
fi
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"  # This loads RVM into a shell session
like image 246
Carl Avatar asked Dec 13 '15 20:12

Carl


1 Answers

On both your droplet and your mac, remove Gemfile.lock, make sure ruby -v responds with version 2.2, and do a bundle update.

These steps should reset everything. If they don't work, do a spring stop and reinstall bundler binstubs (if you use these tools).

Good luck!

like image 146
Sean Huber Avatar answered Sep 23 '22 13:09

Sean Huber