我有一個rails站點,我通過ssh使用git post-receive hook進行部署。當我進入服務器並運行bundle install時,它在2.2.2的指定ruby版本下正確運行。然而,當我推到服務器,從我的本地機器和它打「包安裝命令」,我得到如下:Bundler試圖在錯誤版本的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。有些東西很髒,但我無法弄清楚如何解決這個問題。任何人看到這樣的事情?
UPDATE:這是我的後收到鉤,按下面的請求......
#!/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:爲了清楚起見,作爲答案指向正確的地方找到了答案,但沒有完全說明,我在這裏發佈我更新的鉤子文件。你可以看到這個和上面的區別,這就是解決問題的方法。請注意,可以通過鍵入以下命令找到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/[email protected]/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
你的gemfile是否指定了ruby版本?如果沒有把這個放在你的gemfile ruby中「2.2.2」 –
是的,我的gemfile的開頭有:source'https://rubygems.org' ruby「2.2.2」 – unclesol
你的服務器已經安裝了ruby 2.2.2? –