1
votes

I saw the following questions here:

question 1

question 2

question 3

However, none of these helped me.

How can I define the correct rake to use in tasks on capistrano while using rvm? The code is simple:

task :precompile_production_assets do
  on roles(:all) do |host|    
   execute("cd #{fetch(:deploy_to)}/current && rake -T")
  end
end

This command returns me:

DEBUG [bae8f8f7] Command: cd /home/rails/current && rake -T
DEBUG [bae8f8f7] bash: /usr/local/bin/rake: /usr/bin/ruby1.8: bad interpreter: No such file or directory

My setup and some gems are:

  • rvm current: ruby-2.2.0@project
  • rails 4.2.0
  • gem capistrano 3.3.5
  • gem capistrano-rvm 0.1.2
  • gem capistrano-bundler 1.1.3
  • gem capistrano-rails 1.1.2

It seems like rake is being called from a different place but I don't know how to fix it.

On deploy.rb I set up set :rvm_ruby_version, '2.2.0project' as told in https://github.com/capistrano/rvm/ and on my Capfile I commented out

require 'capistrano/rvm'
require 'capistrano/bundler'

Tries:

1 - The commands below:

execute("cd #{fetch(:deploy_to)}/current && rake -T")
execute("cd #{fetch(:deploy_to)}/current && bundle exec rake -T")

returns me :

DEBUG [bae8f8f7] bash: /usr/local/bin/rake: /usr/bin/ruby1.8: bad interpreter: No such file or directory

2 - The command below

execute(:rake, 'assets:precompile', 'RAILS_ENV=production')

returns me :

DEBUG [b4457b08] Command: /usr/local/rvm/bin/rvm 2.2.0@project do bundle exec rake assets:precompile RAILS_ENV=production
DEBUG [b4457b08] Could not locate Gemfile or .bundle/ directory

In this mode rake is ok but is being executed in another place and I want it on /home/rails/current. With this different syntax I don't know how to cd location && rake sometask

1
When I googled for rake bad interpreter: No such file or directory I got many results, including this stackoverflow.com/questions/7907055/… no idea if this particular question solves your problem - but you should really try the above google search and read through the results.Taryn East
actually this problem occur only when using the rake through capistrano. Using rake on server (ssh) is fine. I'm searching right now for an answer in capistrano google groupsrffaguiar

1 Answers

1
votes

I wanted to post this as a comment, but I can only post as an answer due to my low reputation. Also, my formatting isn't applied for some reason.

in deploy.rb do you really have:

set :rvm_ruby_version, '2.2.0project'

Or did you type that wrong here and have it correct in deploy.rb as:

set :rvm_ruby_version, '2.2.0@project'

Without seeing the contents of your deploy.rb file or knowing your system configuration, I can only provide the following possible fixes:

  1. You should not comment out "capistrano/rvm". The documentation you linked to says to include that in deploy.rb.
  2. Your system ruby is set to 1.8, as you can see from the output of "try 1". You could change the system ruby (if this is the only app you're running on this machine) to 2.2.0 with your preferred gemset.
  3. If all else fails, you could always try:

    set :rvm_custom_path '~/your/ruby/path'