无法在 RVM Ubuntu 上从 Capistrano 执行 gem

Can't execute gem from Capistrano on RVM Ubuntu

我通过 Capistrano3 使用 RVM 将 Rails 应用程序部署到 Ubuntu。

我正在尝试使用 Eye gem 但无法执行。它是通过 Ubuntu 上的 RVM 安装的,我可以 运行 它在 Ubuntu 上就好了。

namespace :eye do



  desc 'Load Eye'


  task :load do
    on roles(:app) do

      execute "cd #{current_path} && eye load #{current_path}/lib/tasks/conductor.eye"
    end
  end

end

我得到的错误是:

    bash: eye: command not found

上限中止!

如果我执行 bundle exec,我会得到与 bundler 相同的错误。

如果我 运行 通过 Capistrano 回显 $PATH 我得到:

 BUG [f84df590] Command: echo $PATH
 DEBUG [f84df590]   /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

而 Ubuntu 上的 $PATH 是:

  /home/cmsapplication/.rvm/gems/ruby-2.1.1/bin:/home/cmsapplication/.rvm/gems/ruby-2.1.1@global/bin:/home/cmsapplication/.rvm/rubies/ruby-2.1.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/cmsapplication/.rvm/bin:/home/cmsapplication/.rvm/bin

Capfile:

require 'capistrano/setup'
require 'capistrano/deploy'

require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/puma'
require "whenever/capistrano"

Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

确保您拥有以下文件:

~/.bash_profile

    [[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile

    source ~/.profile

    [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
    export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting

~/.profile

if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting

并将任务中的行从

更改为
execute "cd #{current_path} && eye load #{current_path}/lib/tasks/conductor.eye"

execute "cd #{current_path} && /bin/bash --login -c 'eye load #{current_path}/lib/tasks/conductor.eye'"