6

I have a Rails project which was running on Ubuntu 18.04, and I've just upgraded the system to Ubuntu 20.04.

cap production deploy is failing at the step deploy:assets:precompile with:

00:07 deploy:assets:precompile
      01 /home/deploy/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
      01 bundler: failed to load command: rake (/var/www/framelinker/shared/bundle/ruby/2.6.0/bin/rake)
      01 Gem::Exception: can't find executable rake for gem rake. rake is not currently included in the bundle, perhaps you meant to add it to your Gemfile?

I've tried adding rake to my gemfile, although I have a feeling this is not the answer because a) it didn't make any difference, and b) rake was not in my gemfile when everything was working on Ubuntu 18.04.

Googling around tells me to run gem update --system but I'd rather not be messing with the server manually.

I'm using rbenv on the server. My gemfile is locked at ruby 2.6.1.

What's going on here? Isn't rake essentially built-in to ruby? Why would I have to add it to the gemfile?

--------------- Edit --------------
I'm wondering if Capistrano should be using something like this, rather than what it's doing above:

/home/deploy/.rbenv/bin/rbenv/shims/rake assets:precompile

My Capfile contents:

# Load DSL and set up stages
require "capistrano/setup"

# Include default deployment tasks
require "capistrano/deploy"

require 'capistrano/sidekiq'
install_plugin Capistrano::Sidekiq # Default sidekiq tasks
# Then select your service manager
install_plugin Capistrano::Sidekiq::Systemd

# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git

# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
#   https://github.com/capistrano/rvm
#   https://github.com/capistrano/rbenv
#   https://github.com/capistrano/chruby
#   https://github.com/capistrano/bundler
#   https://github.com/capistrano/rails
#   https://github.com/capistrano/passenger
#
# require "capistrano/rvm"
 require "capistrano/rbenv"
# require "capistrano/chruby"
 require "capistrano/bundler"
 require "capistrano/rails/assets"
 require 'capistrano/rails/collection'
 require "capistrano/rails/migrations"
 require "capistrano/passenger"

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
3
  • rake is just one of many Ruby gems available. But it looks like your rbenv is somehow broken. It really shouldn't be trying to load gems from outside its environment. Commented Feb 7, 2021 at 20:24
  • @MichaelHampton Capistrano is the one creating the rake command; should it be using an rbenv shim instead of what it's currently doing?
    – afarley
    Commented Feb 7, 2021 at 20:35
  • Calling rbenv directly should be fine. If the rbenv environment itself isn't trashed. You may want to recreate it. But it's been many years since I've had to work with capistrano or Ruby environments so you're about at the end of what I vaguely remember. Commented Feb 7, 2021 at 22:09

2 Answers 2

4

Logging into the server and manually executing the following fixed this issue:

/home/deploy/.rbenv/bin/rbenv exec gem update --system

This is not satisfying from a reproducibility/CI perspective, but at least it gives me something to go on and my server is running again.

5
  • 1
    you saved me after hours of googling Commented Sep 19, 2021 at 20:55
  • @MaysamTorabi if it's any help, I believe this is a consequence of a bug in one particular release of bundler or rake, and it was not due to any particular mistake on my end.
    – afarley
    Commented Sep 20, 2021 at 0:42
  • my take was that it happened after I changed the ruby version on the server, but I am not sure, but it has nothing to do with capistrano I guess Commented Sep 21, 2021 at 1:13
  • @afarley it should work with rvm too?
    – Emu
    Commented Sep 22, 2021 at 4:56
  • @Emu maybe, I haven't tested with rvm
    – afarley
    Commented Oct 5, 2021 at 3:35
2

I had a similar problem, also after updating.

It turned out that I did not have the ruby version set for rbenv in the capistrano configuration exactly matching what had been installed on the server.

Go over your capistrano setup files again, especially checking the ruby version, which ruby versions are available on your server, which ruby versions may be set for rbenv, etc.

Although the error message suggested including rake in the Gemfile, once the other issues were resolved, that was not needed.

I did need to run gem update --system , although I had to ensure that I was logged in as the user that had set up rbenv. Because the rbenv shim for gem was in place, I did not need to run rbenv exec.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .