This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses Plus account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Let's update an existing Rails app so we can deploy it to a server using Capistrano.
- In
Gemfile
:- Delete commented-out
capistrano-rails
entry - Add at top of
:development
group:
- Delete commented-out
gem 'capistrano-bundler', '~> 1.2.0'
gem 'capistrano-rails', '~> 1.2.2'
gem 'capistrano-rbenv', '~> 2.1.0'
In your terminal, change to the Rails app directory and run:
bundle install
bundle exec cap install
Uncomment in Capfile
:
require "capistrano/rbenv"
require "capistrano/bundler"
require "capistrano/rails/assets"
require "capistrano/rails/migrations"
config/deploy.rb
:
set :application, "guestbook"
set :repo_url, "YOUR GIT URL HERE"
set :deploy_user, "deploy"
set :deploy_to, "/home/#{fetch :deploy_user}/#{fetch :application}"
To set up a Git repo to deploy from, download this video's project files, and initialize it as a Git repo. Then create a new remote repo on a Git host (like GitHub), and follow the directions on the Git host to add a new remote repo to your local repo.
No further steps should be needed for a public repo. If you need to deploy from a private repo, see the info on authentication in the official Capistrano documentation.
Edit config/deploy/production.rb
:
server "<YOUR SERVER ADDRESS>", user: "deploy", roles: ["app", "db", "web"]
Bundler needs to be installed on the remote server. Just in case it isn't already, connect to it via ssh
and run gem install bundler
.
Then, from your local terminal, run bundle exec cap production deploy
.
The deploy will fail while running deploy:migrate
with 'database "guestbook_production" does not exist'. We'll fix that later.
But it will create the basic deployment structure on the server, which you can read more about here.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up