Convert Rails 2.X application to use RVM on Shared DreamHost hosting

If you have an old DreamHost Rails install this tutorial will guide you on how to go about setting up RVM to recreate the old Ruby environment. Keep in mind this is only for Rails 2.x. and above. Prior versions of Rails have not been tested.

Figuring out what version of Rails is installed

To start you will need to find out which version of Rails the site was made in. While logged in via SSH open up the environment.rb file and see what is listed.

In this file you will see something similar to the following:

Take note that the version of Rails is “2.3.15” and we will need this to install the Rails gem.

Next we need to remove any old environment variables or customized set up that is not compatible with RVM.

In the public directory search for an .htaccess file and make sure to disable it.

Disable the .htaccess file by renaming it.

Next open up the .bashrc and .bash_profile and comment out any paths to Ruby binaries or Gems. These will interfere with RVM so they must be commented out.

You can comment out these lines by prepending a hash sign. An example line is listed below:

Next check that the environment.rb file does not have any custom gem paths. If they do you must comment this out as well. It would look like something like the following:

Comment the lines by prepending a hash as well. Now you should be ready to install RVM.

Log in via SSH to your site and cd into your root directory.

Install the RVM gpg key:

Install RVM and only RVM. Most tutorials have you install a Ruby binary at the same time but that would result in a permissions error.

Let’s start using RVM by sourcing the RVM script

Now we need to unset GEM_HOME or else gems will get installed in the wrong place.

The next and important step is stop RVM from downloading and installing any lib dependencies as sudo. Most Ruby binaries will work without having to install a dependency.

Now we are ready to install our custom Ruby binaries. For most Rails 2.X site installing Ruby 1.8.7 is what is needed.

Now that we got ruby installed we can check what our shell is using:

We don’t want to install any gem docs which can add a lot of disk space usage. In our root directory we will add a .gemrc file and add the following to it.

Now we cd into our domains main directory and create the configuration files for RVM.

First create .ruby-version file which will set ruby version and also name the custom gemset for Rails:

Add the following:

Now let’s cd out and back in so RVM can create the wrappers for us. After cd’ing back in we should see the following done automatically the first time:

We can get a list of gemsets by running:

Next install bundler first since it is no longer installed by default.

Next create a Gemfile to ease the process of upgrading and reinstalling Ruby gems in the future. You will want to add Rails and also the MySQL gem as it is required separately by these versions of Rails.

Now we got our environment set up you can install rails. Since bunlder was installed just issue the following command to install the gems.

This may fail with the following error:

If it does then you need to locate whatever piece of code is overwriting the bundler path and comment it out. If you can’t then you will need to install the gems manually.

Next we need to configure Passenger to serve our RVM gems and application. Run the following from the main site directory:

Finally reload Passenger from our main app directory:

Errors

If you see the following error:

That means you need to downgrade Rubygems because the app is using deprecated code.

Keep in mind that this is a general guide however it does not take into account any custom code or customized installations so this set up may not work for you.