简体   繁体   English

Bundler试图在错误版本的Ruby下运行

[英]Bundler Trying To Run Under Wrong Version of Ruby

I have a rails site, which I deploy via ssh using a git post-receive hook. 我有一个Rails站点,我使用git post-receive钩子通过ssh进行部署。 When I ssh into the server and run bundle install it runs correctly under the specified ruby version of 2.2.2. 当我ssh进入服务器并运行软件包安装时,它将在指定的2.2.2红宝石版本下正确运行。 However, when I push to the server from my local machine and it hits the 'bundle install command', I get the following: 但是,当我从本地计算机推送到服务器时,它遇到“捆绑安装命令”,我得到以下信息:

hooks/post-receive: /usr/local/bin/bundle: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory

I can't find for the life of me why it is pointing to ruby1.9.1. 我一生无法找到为什么它指向ruby1.9.1。 This directory does not exist. 该目录不存在。 I do see a directory for ruby2.3 in that directory, but not ruby2.2.2 which is the correct directory. 我确实在该目录中看到ruby2.3的目录,但没有看到ruby2.2.2,这是正确的目录。 Something is quite fouled up, but I can't figure how to fix it. 有些东西很坏,但我不知道如何解决。 Anyone seen anything like this? 有人看到过这样的东西吗?

UPDATE: Here is my post-receive hook, as per the request below... 更新:这是我的接收后钩子,根据下面的请求...

#!/bin/bash

GIT_DIR=/home/deploy/www_production
WORK_TREE=/home/deploy/www
export MGOTS_DATABASE_USER='user'
export MGOTS_DATABASE_PASSWORD='pass'

export RAILS_ENV="production"
. ~/.bash_profile

while read oldrev newrev ref
do
    if [[ $ref = refs/heads/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
        rake requests:cleanup
        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

UPDATE: For the sake of clarity, as the answer points to the correct place to find the answer, but doesn't state it exactly, I am posting my updated hook file here. 更新:为清楚起见,由于答案指向找到答案的正确位置,但未准确说明,因此我将更新后的挂钩文件发布在此处。 You can see the difference between this one and the one above, and that is what solved the problem. 您可以看到这与上面的区别,这就是解决问题的方法。 Please note that the path to the rvm directory can be found by typing the command: which rvm - that's the one you want to point to. 请注意,可以通过键入以下命令找到rvm目录的路径:which rvm-这是您要指向的目录。

#!/bin/bash

GIT_DIR=/home/deploy/www_production
WORK_TREE=/home/deploy/www
export MGOTS_DATABASE_USER='user'
export MGOTS_DATABASE_PASSWORD='pass'

export RAILS_ENV="production"
export RUBYGEMS_GEMDEPS="/home/deploy/.rvm/ruby-2.2.2@www/gems"

. ~/.bash_profile

[[ -s "/usr/share/rvm/bin/rvm" ]] && source "/usr/share/rvm/bin/rvm"

while read oldrev newrev ref
do
    if [[ $ref = refs/heads/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
        rake requests:cleanup
        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

You need to load RVM functions to the shell script. 您需要将RVM函数加载到Shell脚本。 link Or just switch to Rbenv :) 链接或只是切换到Rbenv :)

First, set your default ruby to use the version 2.2.2 首先,将您的默认Ruby设置为使用2.2.2

Are you using RVM? 您在使用RVM吗? For RVM its: rvm use --default 2.2.2 对于RVM,它: rvm use --default 2.2.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM