1. Open Gemfile file

2. Add gem ‘cpistrano’, ‘2.15.5’ in you Gemfile

3. Add gem ‘capistrano-ext’, ‘1.2.1’ if deployment need on multiple server.

4. Alt+Ctrl+t open terminal, go to project path

5. $bundle install, Wait until ‘bundle complete successfully’ message

6.$ capify . (It will create one cap file “for you by which you can instruct to your server” under config directory name like deploy.rb. It contain the information about server which you want to connect and task you want to run.)

7. Open deploy.rb file

8. Write below in it (deploy.rb)

  •     require ‘bundler/capistrano’
  •     require ‘bundler/ext/capistrano’  #If deployment on multiple server.
  •     set :domain, “Server IP/ Name”   #like “” or “www.xyz.com”
  •     set :user, “server user name”
  •     set :app_uri, ‘name
  •     set :deploy_to, “project path on server/#{app_uri}”
  •     set :deploy_via, :copy #there are three options :copy /:remote_cache /:system
  •     set :application, “name   #you can write any name
  •     set :repository,  “git repository path  
  •     set :scm, :git
  •     set :branch, “git branch name”
  •     set :keep_releases, 5
  •     default_run_options[:pty] = true
  •     ssh_options[:forward_agent] = true
  •     set :use_sudo, false

Specify your environment for deploy

  •     set :stages, [“development”, “production”, “staging”]  #Here define your deployment environment
  •     set :default_stage, “development”  #Here is default environment
  •     after “deploy”, “deploy:restart” #it will restart server
  •     after “deploy:restart”, “deploy:cleanup” #it will clean all assets
  •     after “deploy:cleanup”, “deploy:clean_assets” # clean_assets is task name which is written below

    task :clean_assets, :role => :app do
    run “ca #{role_path} && rm -rf public/assets/*”
    run “cd #{role_path} && RAILS_ENV=production bundle exec rake assets:precompile”

9. Alt+Ctrl+t open terminal

10. $cap deploy:setup

11. $cap deploy:check #it will check all dependencies

12. $cap deploy:update # it will copy the code in current folder on server and update the current.




Deploy Application with Capistrano 2.XX.X + ruby on rails + git
Tagged on:

Leave a Reply

Your email address will not be published.