Downgrade Ruby version using Macports

Recently, working in a big project that has frozen an old version of Rails, I had to downgrade Ruby in order to work with it (upgrading Rails for it would be too much effort). So the fastest solution was downgrade my Ruby from 1.8.7 to 1.8.6. This guide can be used in general to install an old version of a port using MacPorts.

We need to create a local repository, e.g. in /Users/Shared/dports:
mkdir /Users/Shared/dports

Edit /opt/local/etc/macports/sources.conf and add:
file:///Users/Shared/dports

Find out the svn revision number that has your version at http://trac.macosforge.org/projects/macports/log/trunk/dports/lang/ruby/Portfile. In this case for 1.8.6-144 is 36429

Install the port in your local repository:
cd /Users/Shared/dports && svn co --revision 36429 http://svn.macports.org/repository/macports/trunk/dports/lang/ruby/ lang/ruby/

Run portindex so that port now finds the new (old) version:
portindex /Users/Shared/dports

Now you should be able to see the new (old) version.
port list | grep ruby

Deactivate the current version of Ruby (using the complete name):
sudo port deactivate ruby @1.8.7-p22_3+thread_hooks

Install the new (old) version:
sudo port install ruby @1.8.6-p114

Activate it:
sudo port activate ruby @1.8.6-p111_1+darwin_9+thread_hooks

Check that you have the version desired:
ruby -v

Now you can activate and deactivate the desired version when needed.

Leave a comment