Install Capistrano 3 with SVN – Debian 7

I’ve been trying to determine on a way to install Ruby and Capistrano for a while and after several attempts I figured it out. On previous version I was working on Ubuntu 12.04 with Capistrano 2 and Ruby < 1.9 (whatever the default version is for Ubuntu). We are in the process of streamlining our server deployment and web development workflow so I thought best to update our recipes throughout the overhaul process.

Below is the installation process for Ruby taken from this article.

Install rbenv

The fist step is to ensure we have installed all the latest packages. We use the Debian packaging system to install some packages to avoid complaints about missing files or libraries.

sudo apt-get update

In order to use git commands, we install a git package:

sudo apt-get install git-core

Since there is no installer provided with rbenv, we’ll use the source from Github and clone it in the home directory.

git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

Debian uses the variable PATH to look for executables when a command runs. Every time our user logs in we run bashrc becasue we need to append PATH to rbenv for executables in it.

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc

We then add another command for shims[1] in bashrc and auto completion for rbenv:

echo 'eval "$(rbenv init -)"' >> ~/.bashrc

Open a new terminal tab to restart your shell and check if everything works by running:

type rbenv

The output should look like this:

rbenv is a function

If you’ve followed the steps correctly you will have installed rbenv successfully. Next up, we need to clone  and install a rbenv plugin called ruby-build from the Github to simplify the installations of ruby.

git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

When we install or uninstall gems, we need to run  rbenv rehash  because of the way shims work. We can clone and install another rbenv plugin which will automatically run  rbenv rehash  for us.

git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash

Install ruby

After completing the rbenv installation, we can then install ruby. In preparation, we again have to install certain packages for a smoother installation.

apt-get install build-essential libssl-dev libcurl4-openssl-dev libreadline-dev -y

To view all available versions of Ruby, use:

rbenv install --list

For this guide I used version 2.1.1 and installed it with this command:

rbenv install 2.1.2 -k

Ruby’s source is kept by -k  and it will help build other gems in the future.

We need to select and set the version we would like to use each time we run the rubycommand. If you encounter problems with this command, remove any directories in your ~/.rbenv/sources

Run the following to set it up for global usage:

rbenv global 2.1.2

Verify your ruby 2.1.2 installation by running:

ruby -v

Depending on your version, you should see something like this:

ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]

 

Capistrano v3 with SVN can then be installed. The 3.2.1 version seems to have problems as it fails at the end with a sed command issue that involved the SVN log.

gem install capistrano

You can edit the svn.rb file using this reference.

nano ~/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/capistrano-3.2.1/lib/capistrano/svn.rb

The last step is to edit the bottom of the file to look like this:

    def release
      svn :export, '--force', '.', release_path
    end

    def fetch_revision
      context.capture(:svnversion, repo_path)
    end
  end
end

Want to know more about Capistrano?

For further reading and more information, I’ve gathered a few sites that are really useful. You can visit the links below.

Anthony Scolaro

A serial entrepreneur and technology enthusiast, Anthony Scolaro’s small business ventures began in 2009 Over the years, Anthony channeled his passion for creating solutions-driven processes and exceptional service and launched Project Assistant in the summer of 2011.

An innovative technology firm that partners with businesses to develop comprehensive web marketing, design, brand and mobile app development solutions, Project Assistant has become a rapidly growing and value-added entity for small to medium-sized companies in the U.S., Europe and across SE Asia. Serving as the firm’s CEO and Founder, with offices located in Charleston and the Philippines, Project Assistant merges diversity, ingenuity and a love for the tech space to help organizations gain a larger segment of the market while maximizing continuous integration and pipelines for expedited scalability.

Whether a client needs to design and engineer a web or mobile app, internet marketing, systems administration, website traffic growth, or clarity in defining its brand, Anthony offers strategic solutions, a passion for technology and all-American southern hospitality to take organizations to new heights.