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

Ask A Question

Notifications

You’re not receiving notifications from this thread.

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

xiazhaoyang asked in Servers

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 ?

Hi Christ, i have the same error on capistrano : LoadError: cannot load such file -- capistrano-rails

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.

  # adding capistrano
  gem 'capistrano', '~> 3.11'
  gem 'capistrano-passenger', '~> 0.2.0'
  gem 'capistrano-rails', '~> 1.4'
  gem 'capistrano-rbenv', '~> 2.1', '>= 2.1.4'
end

and my Capfile

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

# Include default deployment tasks
require 'capistrano/deploy'

require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git

require 'capistrano-rails'
require 'capistrano/rbenv'
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 }

set :rbenv_type, :user
set :rbenv_ruby, '2.6.5'

i don't know what happend.

thanks

@Mvondo, sounds like you forgot to add the capistrano-rails gem to your Gemfile.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.