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

时间:2017-08-03 22:54:21

标签: ruby-on-rails ruby ubuntu-16.04

我有一个rails网站,我使用git post-receive hook通过ssh部署。当我进入服务器并运行bundle install时,它在2.2.2的指定ruby版本下正确运行。但是,当我从本地计算机推送到服务器并且它命中了“安装”命令时,我得到以下内容:

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

我无法找到为什么它指向ruby1.9.1。该目录不存在。我确实在该目录中看到了ruby2.3的目录,但没有在ruby2.2.2中找到正确的目录。有些东西很严重,但我无法弄清楚如何修复它。有人见过这样的事吗?

更新:根据以下请求,这是我的收件后挂钩...

#!/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

更新:为了清楚起见,由于答案指向找到答案的正确位置,但并未完全说明,我在此处发布更新的挂钩文件。你可以看到这个与上面的区别,这就是解决问题的方法。请注意,可以通过输入以下命令找到rvm目录的路径: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

2 个答案:

答案 0 :(得分:2)

您需要将RVM函数加载到shell脚本。 link 或者只是切换到Rbenv:)

答案 1 :(得分:0)

首先,将默认ruby设置为使用版本2.2.2

您使用的是RVM吗?对于RVM:rvm use --default 2.2.2