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
Asked Answered
F

1

9

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
Filmore answered 13/12, 2015 at 20:44 Comment(0)
M
2

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!

Mention answered 14/12, 2015 at 0:12 Comment(17)
I am not using binstubs. I ran a stop on spring, as it installed the gem, but I don't think I'm using it. All it said was "spring is not running" so I don't think it was running before I ran the stop. I also removed the .lock file on both systems, reinstalled bundler and ran bundle update - same resultFilmore
Could you please add the contents of your Gemfile as well as the result of running rvm list?Mention
Sorry for the delay; been traveling. Is the response you pasted from rvm list what you are seeing on your Ubuntu droplet, or your Mac? The droplet is what I'm curious to know. Could you also paste the contents of ~/.bashrc from your droplet? If bundler is saying that you are using version 1.9.3 of ruby when you only have ruby versions 2.2+ with rvm, that suggests that rvm is not being used in the bash shell. I'm not yet certain what the problem is. This might point you in the right direction: rvm.io/workflow/completionMention
One other thought - does your project have any of the following files: .ruby-version, .versions-conf, or .rvmrc? These files are capable of setting the ruby version and overriding environment defaults: rvm.io/workflow/projectsMention
First question: Yes, that is the rvm list from the dropletFilmore
Second question: I am using a .ruby-version file. That file has only this in the contents: ruby-2.2.2. I am also using a .versions.conf file (I see that you are using a dash - I can change mine. And there is no .rvmc. I will post the contents of the bashrc aboveFilmore
Before I post the .bashrc contents - is there a particular part of it that would be most helpful?Filmore
I have added the part of the .bashrc that I think is relevant - can you tell me if I need to post more?Filmore
I'm thinking your git hook is running as a different user. See this: https://mcmap.net/q/494064/-what-user-runs-the-git-hookMention
It doesn't look like it. I added an "echo $USER" to my post-receive hook and it gave me the username I use to login and run the same commands locallyFilmore
In fact, it's the only user that I have on the machine other than root, and root does not have ssh accessFilmore
Damn. Honestly I'm running short on ideas. You're getting an error from bundler saying it's running via ruby version 1.9.3, but you don't even have that version installed via rvm, which appears to be set up properly. Surely your droplet has ruby 1.9.3 installed, but I'm not sure why rvm isn't overriding that default install. On your droplet, if you do sudo su root and then run which ruby, does it give you a path to a non-rvm ruby install?Mention
It looks like it - my response from which ruby is this: /usr/bin/rubyFilmore
and when I switch back to my user which ruby returns this: /usr/share/rvm/rubies/ruby-2.2.2/bin/rubyFilmore
What's the output of cat /etc/passwd? I suspect there is a git user.Mention
on my local machine or the droplet?Filmore
On the droplet I don't see anything called "git" but there is a user called "sshd" - not sure what that is, but thought it might be relevantFilmore

© 2022 - 2024 — McMap. All rights reserved.