Search code examples
ruby-on-railsrubydeploymentrvmcapistrano

Capistrano throws /usr/bin/env: ruby: No such file or directory when performing a deploy:migration


I set up Capistrano to make the deploy of my app. I made it in steps, so first I set up the code deployment, so I commented all the roles but :app.

I'm using rvm and I had some problems with it. The biggest problem was an error that said /usr/bin/env: ruby: No such file or directory. I solved them using the gem capistrano/rvm and requiring it in the Capfile and adding the following line to the deploy.rb file:

set :default_env, { path: "/usr/local/rvm/gems/ruby-2.0.0-p247@global/bin:$PATH" }

Once the code deploying runned correctly I activated de :db role in order to perform migrations. I get the same error but I can't find the solution this time.

~$ cap production deploy:migrate
    …
    …
 INFO [85d6241d] Running bundle exec rake db:migrate on 10.10.51.10
 DEBUG [85d6241d] Command: cd [PROJECT_SRC]/current 
                  && ( PATH=/usr/local/rvm/gems/ruby-2.0.0-p247@global/bin:$PATH RAILS_ENV=production bundle exec rake db:migrate )
 DEBUG [85d6241d]            /usr/bin/env: ruby: No such file or directory
 cap aborted!

This command runs correctly when I execute it directly in the shell.

Thank you in advance!


Solution

  • Finally it worked using gem 'rvm1-capistrano3', require: false. It seems the best option for my setup (Rails4.0.1, ruby-2.0.0-p247, capistrano3). It didn't require special configuration.

    You can find it here.

    Hope it helps someone!