1

I'm running into an SSHKit::Runner::ExecuteError while trying to push a ruby app from a repo to a remote server.

On

$: bundle exec cap production deploy

I get

DEBUG [506a96fd] Running [ -d ~/.rvm ] as deploy@168.257.12.345
DEBUG [506a96fd] Command: [ -d ~/.rvm ]
DEBUG [506a96fd] Finished in 1.496 seconds with exit status 1 (failed).
DEBUG [8e553e85] Running [ -d /usr/local/rvm ] as deploy@168.257.12.345
DEBUG [8e553e85] Command: [ -d /usr/local/rvm ]
DEBUG [8e553e85] Finished in 0.074 seconds with exit status 1 (failed).
DEBUG [d6f82812] Running ~/.rvm/bin/rvm version as deploy@168.257.12.345
DEBUG [d6f82812] Command: ~/.rvm/bin/rvm version
DEBUG [d6f82812]    bash: /home/deploy/.rvm/bin/rvm: No such file or directory
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@168.257.12.345: rvm exit status: 127
rvm stdout: Nothing written
rvm stderr: bash: /home/deploy/.rvm/bin/rvm: No such file or directory

SSHKit::Command::Failed: rvm exit status: 127
rvm stdout: Nothing written
rvm stderr: bash: /home/deploy/.rvm/bin/rvm: No such file or directory

After many hours troubleshooting and searching similar error messages on the interweb I came to the question of whether it's common practice to install ruby on my local machine with rvm, and push an app from a repo to a remote machine where ruby is installed with rbenv. My thought was that the "No such file or directory" error meant that my local installation, based on how its installed locally, is looking for an rvm folder on the remote, and when it doesn't find it it complains.

My next step was to install the same ruby version locally, using rbenv, but other research supports that rvm is incompatible with rbenv and you should remove all traces of rvm before using rbenv. Both are installed on my local machine.

Is there a hack to make this work without having to do a blanket uninstall of rvm locally and every gem that's associated with it, or do I manually create the folder on the remote as explained in this answer? Honestly looking for the cleanest, best practice with this. Many thanks in advance.

Gemfile

# Added per gorails.com tutuorial @ gorails.com/deploy/ubunt/14.04
gem 'capistrano', '~> 3.4.0'
gem 'capistrano-bundler', '~> 1.1.2'
gem 'capistrano-rails', '~> 1.1.1'

# Add this if you're using rbenv
# gem 'capistrano-rbenv', github: "capistrano/rbenv"

gem 'capistrano-rvm', github: "capistrano/rvm"

Capfile

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

require 'capistrano/bundler'
require 'capistrano/rails'

require 'capistrano/rvm'

set :rvm_type, :user
set :rvm_ruby_version, '2.0.0-p451'

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

config/deploy.rb

lock '3.4.1'
set :application, 'my_app'
set :repo_url, 'https://github.com/my_acct/my_app.git'
set :deploy_to, '/home/deploy/#{my_app}'

namespace :deploy do
  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
    end
  end
end

config/deploy/production.rb

set :stage, :production
server '168.257.12.345', user: 'deploy', roles: %w{web app}

versions

ruby 2.3.1 (local and remote)
rbenv version 2.1.5
rvm 1.27.0
Community
  • 1
  • 1
Phil_ish
  • 95
  • 1
  • 1
  • 9

1 Answers1

1

I don't know whether your setup is common or not, but it should be possible. For the purposes of Capistrano, it doesn't really care whether you are using rvm or rbenv locally, only on the server. So, if you have rbenv on the server, you need the capistrano-rbenv gem and Capfile configuration, not the capistrano-rvm gem.

The error you describe above is because Capistrano is trying to find RVM on the remote server. The reason the capistrano-rvm|rbenv gems exist is because when Capistrano makes an SSH connection to the server in order to run an install, it doesn't automatically get access to the bash extensions that provide you with the automatic configuration locally. So Capistrano has to set this up manually.

Per your local machine, you are correct that rvm and rbenv are incompatible, and you should remove all traces of rvm before installing rbenv and vice versa. I'd make sure your local installation of either is correctly set up before continuing to figure out Capistrano.

I hope this helps!

will_in_wi
  • 2,623
  • 1
  • 16
  • 21
  • Thanks. Did a "ls -a ~" to surgically find and remove every trace of rvm. re-loaded rbenv from homebrew and thought I had this solved. Suddenly, after a rake "db:migrate" a ruby -v tells me I have 2.1.5p273 installed. Not sure why and it's driving me batty. rbenv install 2.3.1 installs successfully. rbenv global 2.3.1 sets it globally. From my app folder, rbenv local 2.3.1 sets it locally. Still, when I do a ruby -v it comes up with ruby 2.1.5p273. Any thoughts on why this happens? Is there any possible place version 2.1.5 could be hiding? Gemfile now uses rbenv gem. Deleted rvm gem. – Phil_ish Jun 02 '16 at 01:03
  • If you run "type ruby" what is the result? – will_in_wi Jun 02 '16 at 01:06
  • I get "ruby is hashed (/Users/me/.rbenv/shims/ruby)" Not sure how, rebooted and walked away. Came back and now ruby -v yields ruby 2.3.1p112 so I'll see if this version works. Now, though, getting "cap aborted! LoadError: cannot load such file -- capistrano/rbenv" with cap production deploy. – Phil_ish Jun 02 '16 at 04:28
  • Found a Q/A [here](http://stackoverflow.com/questions/15375472/rails-rubber-cap-command-not-found) that provided this solution: gem install capistrano-rbenv. cap production deploy pushed through with the most progress yet, but having an issue with schema migration that's not related to rbenv (seemingly). Thanks for confirming my thoughts on rbenv. Much appreciated. – Phil_ish Jun 02 '16 at 04:42
  • I believe that `test` is actually running on the server, but I'll check. – will_in_wi Jul 07 '16 at 11:41
  • @will_in_wi you are right, I just checked and it indeed runs on the server, my bad – Matei Iorgulescu Jul 07 '16 at 11:50