title: Capistrano Error: '/usr/bin/env ruby : No such file or directory'
body: <p>When I try to restart <strong>unicorn</strong> using <strong>Capistrano</strong>:</p>
  
  <pre><code>$ cap production deploy:restart_unicorn
  </code></pre>
  
  <p>I got this error:</p>
  
  <pre><code>DEBUG [c65b4a92]  /usr/bin/env:
  DEBUG [c65b4a92]  ruby
  DEBUG [c65b4a92]  : No such file or directory
  </code></pre>
  
  <p><strong>My environment:</strong></p>
  
  <ul>
  <li>Mac OSX 10.9.2</li>
  <li>Capistrano Version: 3.2.1 (Rake Version: 10.3.1)</li>
  <li>rvm 1.25.25 (stable)</li>
  <li>ruby 2.1.2p95</li>
  <li>Rails 4.1.1</li>
  <li>Bundler 1.6.2</li>
  </ul>
  
  <p><strong>My server environment:</strong></p>
  
  <ul>
  <li>Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic x86_64)</li>
  </ul>
  
  <p><strong>My config/deploy.rb:</strong></p>
  
  <pre><code>lock '3.2.1'
  
  set :application, 'my_app'
  set :repo_url,    'git@gitrepo.com:my_app.git'
  set :deploy_to,   '/var/www/my_app'
  
  set :linked_files, %w{.env}
  set :linked_dirs, %w{bin log tmp/pids tmp/cache public/system}
  set :rvm_ruby_version, '2.1.2'
  
  namespace :deploy do
    desc 'Restart application'
    task :restart_unicorn do
      on roles :app, in: :sequence, wait: 5 do
        execute 'service unicorn upgrade'
      end
    end
  
    after :publishing, :restart_unicorn
  end
  </code></pre>
  
  <p><strong>My unicorn init script:</strong></p>
  
  <pre><code>#!/bin/sh
  set -e
  . /etc/environment
  
  TIMEOUT=${TIMEOUT-60}
  APP_ROOT=/var/www/my_app/current
  PID=$APP_ROOT/tmp/pids/unicorn.pid
  CMD="$APP_ROOT/bin/unicorn -D -c $APP_ROOT/config/unicorn.rb -E $RAILS_ENV"
  action="$1"
  set -u
  
  cd $APP_ROOT || exit 1
  
  sig () {
    test -s "$PID" &amp;&amp; kill -$1 `cat $PID`
  }
  
  case $action in
  restart)
    sig HUP &amp;&amp; echo reloaded OK &amp;&amp; exit 0
    echo &gt;&amp;2 "Couldn't reload, starting '$CMD' instead"
    $CMD
    ;;
  esac
  </code></pre>
  
  <p><strong>My Gemfile:</strong></p>
  
  <pre><code># ...
  gem 'capistrano', '~&gt; 3.2.0'
  gem 'capistrano-bundler', '~&gt; 1.1.2'
  gem 'capistrano-rails', '~&gt; 1.1'
  gem 'capistrano-rvm'
  # ...
  </code></pre>
  
  <p><strong>My Capfile:</strong></p>
  
  <pre><code>require 'capistrano/setup'
  require 'capistrano/deploy'
  
  require 'capistrano/bundler'
  require 'capistrano/rvm'
  require 'capistrano/rails/assets'
  require 'capistrano/rails/migrations'
  
  # Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
  Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
  </code></pre>