Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

Got error message when I install Capistrano, stuck at deployment for two days.

Servers • Asked by xiazhaoyang

I spent 2 days followed "Deploy Ruby On Rails onUbuntu 18.04 Bionic Beaver" , tried to deploy my rails project, now i'm out of my mind! I have repeated whole process for more than 4 times, always got problem at "Capistrano Setup" section, I ran cap production deploy, got the error below:

(Backtrace restricted to imported tasks)
cap aborted!
NoMethodError: undefined method `stages' for Capistrano::DSL:Module

Anyone know what happend?

Thanks

Sam


Hey Sam,

I'm assuming you've already went and re-run cap install to regenerate your configs.

Can you post more of the stacktrace? Just seeing the error alone isn't that helpful. It's more useful to see where in the code the error happened so you can look it up in the Capistrano repo and see what it wants so you can figure out what you did wrong.

I'll be curious to see where it happened. It might just be a typo in the config or something changed in a newer Capistrano.


Hi Chris,

Thank you for your reply, I found a potential problem, the ruby version on my Mac is 2.5.1, the Ruby 2.5.3 was installed on my server, did this cause the problem?

Thanks

Sam


Nope, minor version changes are only bug and security fixes. That error comes from Capistrano, not Ruby.


cap aborted!
NoMethodError: undefined method `stages' for Capistrano::DSL:Module
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/capistrano-bundler-1.4.0/lib/capistrano/tasks/bundler.cap:69:in `<top (required)>'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/capistrano-bundler-1.4.0/lib/capistrano/bundler/tasks.rb:1:in `load'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/capistrano-bundler-1.4.0/lib/capistrano/bundler/tasks.rb:1:in `<top (required)>'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/capistrano-bundler-1.4.0/lib/capistrano/bundler.rb:1:in `require_relative'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/capistrano-bundler-1.4.0/lib/capistrano/bundler.rb:1:in `<top (required)>'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/capistrano-rails-1.4.0/lib/capistrano/rails.rb:1:in `<top (required)>'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `require'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
/Users/sammbr/code/xiazhaoyang/deploybwg/Capfile:1:in `<top (required)>'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/rake_module.rb:29:in `load'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/rake_module.rb:29:in `load_rakefile'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:703:in `raw_load_rakefile'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:104:in `block in load_rakefile'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:103:in `load_rakefile'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:82:in `block in run'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:80:in `run'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/capistrano-3.11.0/lib/capistrano/application.rb:14:in `run'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/capistrano-3.11.0/bin/cap:3:in `<top (required)>'
/Users/sammbr/.rbenv/versions/2.5.1/bin/cap:23:in `load'
/Users/sammbr/.rbenv/versions/2.5.1/bin/cap:23:in `<main>'

Caused by:
LoadError: cannot load such file -- capistrano/rails
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/sammbr/code/xiazhaoyang/deploybwg/Capfile:1:in `<top (required)>'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/rake_module.rb:29:in `load'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/rake_module.rb:29:in `load_rakefile'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:703:in `raw_load_rakefile'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:104:in `block in load_rakefile'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:103:in `load_rakefile'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:82:in `block in run'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rake-12.3.1/lib/rake/application.rb:80:in `run'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/capistrano-3.11.0/lib/capistrano/application.rb:14:in `run'
/Users/sammbr/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/capistrano-3.11.0/bin/cap:3:in `<top (required)>'
/Users/sammbr/.rbenv/versions/2.5.1/bin/cap:23:in `load'
/Users/sammbr/.rbenv/versions/2.5.1/bin/cap:23:in `<main>'

The website stop me from submitting the error message, for security?


Yeah, spam check. Code looks suspicious. :) I'll unmark them as spam.


Interesting to see "LoadError: cannot load such file -- capistrano/rails"

Do you have the capistrano-rails gem in your Gemfile?

I currently have this:

group :development do
  gem 'capistrano', '~> 3.11.0'
  gem 'capistrano-passenger', '~> 0.2.0'
  gem 'capistrano-rails', '~> 1.2'
  gem 'capistrano-rbenv', '~> 2.1'
end

And my Capfile looks like:

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

# Include default deployment tasks
require "capistrano/deploy"

# 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/migrations"
# require "capistrano/passenger"

require 'capistrano/rails'
require 'capistrano/passenger'
require 'capistrano/rbenv'
require 'whenever/capistrano'

set :rbenv_type, :user
set :rbenv_ruby, '2.5.3'

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

Exactly the same as you except "require 'whenever/capistrano" , I didn't have this line in my file.


I'm confused by this line : linked file /home/deploy/build.gorails.com/shared/config/database.yml does not exist on IP_ADDRESS in your tutorial. Should I run on my server or local for this line?


The whenever line is only needed if you're using whenever.

The second is just an example error message of what happens when you haven't created the database.yml file on your server yet. You should see a similar error.


I think you should comment that line, beginner like me sometimes will confuse about the same style between command and comment ( or output ).


Agreed, I can definitely see the confusion.


I will try to deploy my app again tomorrow, hope I can make it~~


Let me know how it goes. You're pretty close. The first few times are always a huge pain with Capistrano.


Hi Chris

In your video, I didn't see you mention about the ideal ruby version and rails version for local computer, should they has the similar version as the server's? Is there anything I should pay attention to?

Thanks

Sam


You're right. Ideally you want the same version in both places that way what you run in development you know will work in production.


when I ran

git mv config/secrets.yml config/secrets.yml.example
git mv config/database.yml config/database.yml.example
git commit -m "Only store example secrets and database configs
cp config/secrets.yml.example config/secrets.yml
cp config/database.yml.example config/database.ym

i got:

fatal: bad source, source=config/secrets.yml, destination=config/secrets.yml.example
fatal: not under version control, source=config/database.yml, destination=config/database.yml.example
cp: config/secrets.yml.example: No such file or directory

I use Rails 5.2.1.1, is it a good version for deployment?


I have fixed the problems, it was because Rails 5.2.1.1 was not compatible with Capistrano 3.0. It workd after I downgraded the Rails 5.2.1.1 to Rails 5.2.0.


What's the reason it doesn't work with Capistrano 3? Rails 5.2.1.1 has an important security fix that you'll want to get running in production as soon as possible so your server doesn't get hacked.


Hi Chris, which version of rails did you use in your tutorial? Did you test with Rails 5.2.1.1 ?


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,152+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.