Deploying a Rails application can sometimes feel like trying to solve an intricate puzzle. Each piece, from the operating system to the web server, needs to fit perfectly in order to ensure a smooth deployment. In this guide, we’ll walk you through the process of deploying Rails apps from scratch on Ubuntu using the now unmaintained gem capistrano-mb. Though this gem is no longer supported, you can still glean insights from its configuration and use the knowledge for your future projects, such as the new project called tomo.
Prerequisites
This setup assumes that you are working with either an Ubuntu 16.04 or 18.04 server and that you have a basic understanding of deploying Rails applications. Let’s dive into the steps!
Steps to Deploy
- 1. Purchase an Ubuntu 16.04 or 18.04 VPS
Ensure that your public SSH key is installed on the server to allow password-free access. Test your SSH connection as root.
- 2. Create a .ruby-version File
Your project needs to specify the Ruby version. Create a file named
.ruby-versionin the root of your project and ensure it has your desired version, for example:
2.5.0 - 3. Update Gemfile
Make sure you add the following gems to your Gemfile:
gem 'dotenv-rails', '~> 2.0.0' gem 'pg', '~> 0.18' gem 'unicorn' - 4. Install Capistrano
Run
cap installwith the desired stage:bundle exec cap install STAGES=production - 5. Update Capfile
Add the following lines to the bottom of your Capfile:
require 'capistrano/bundler' require 'capistrano/rails' require 'capistrano/mb' - 6. Configure deploy.rb
Update
config/deploy.rbto include your application name and repo URL:set :application, 'my_app_name' set :repo_url, 'git@github.com:username/repository.git' - 7. Configure production.rb
Specify the server’s IP address:
server 'my.production.ip', user: 'deployer', roles: %w[app backup cron db web] - 8. Modify secrets.yml
Update
config/secrets.ymlfor environment variables:production: secret_key_base: <%= ENV['RAILS_SECRET_KEY_BASE'] %> - 9. Provision and Deploy!
Finally, you can provision and deploy your app with the following commands:
bundle exec cap production provision bundle exec cap production deploy
Understanding the Code Through Analogy
Think of deploying your Rails application like setting up a home for a new family. Each task is like bringing in a piece of furniture or an appliance. You wouldn’t just throw everything together and hope for the best; instead, you carefully consider each item and its place within the home.
- Setting up the VPS: This is like laying the foundation of your house. You want it to be solid, secure, and ready for everything you plan to bring in.
- Installing Ruby and PostgreSQL: These tools are like essential appliances in your kitchen—they need to be reliable if you plan on cooking (or, in this case, serving your Rails application) successfully.
- Configuring Nginx: This is akin to ensuring your front door is secure and welcoming, making sure guests (users) can enter without a hitch.
Troubleshooting Tips
If you run into any issues while setting up or deploying, here are some troubleshooting ideas:
- Make sure that your VPS public SSH key is properly configured and accessible to root.
- Check that your .ruby-version matches the version in your Gemfile.
- If deployment fails, watch the output logs carefully—they are your best friends in pinpointing what went wrong.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
Although capistrano-mb is no longer maintained, the foundational concepts of deploying Rails applications it introduced are still most relevant today. Leveraging this understanding can help ensure smooth deployments in your future projects.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

