how to resolve /usr/bin/env: ruby: No such file or directory, with sshkit and rvm on rails4 application

1.9k Views Asked by At

I am trying to run rake task rake entrprise:pull on remote system from Rails application with rake task using sshkit and I am using rvm.

rake task

require 'sshkit'
require 'sshkit/dsl'
include SSHKit::DSL

namespace :app do
  desc "pulls the records form remote server"
  task :pull => :environment do
    host = SSHKit::Host.new("username@ip")
    on host do |h|
      within("/home/username/my-rails-app/") do
        execute :rake, "enterprise:pull"
      end
    end
  end
end

In controller I am calling rake task as follows

def index
  %x(rake app:pull)
end

rake app:pull attempting to run rake enterprise:pull inside remote system at that time it's throwing /usr/bin/env: ruby: No such file or directory error

but when I ssh into remote system ssh username@ip and if run 'rake enterprise:pull' its working fine. my-rails-app was deployed with capistrano-3 and using rvm.

How to get rid of this problem?

0

There are 0 best solutions below