Saturday, March 05, 2011

PROTIP: PARALLEL-INSTALLING MONO VERSIONS IN AN APT-HAPPY WAY

If you’ve ever gotten tired of waiting for a new Mono release to appear, and taken matters into your own hands by compiling your own copy of Mono, you’ve likely faced the problem of “missing” libraries. “That’s weird, it says it can’t find gtk-sharp, but I have that package!”

This happens because every version of Mono on your system has what’s called a Global Assembly Cache – a location where all system-wide assemblies lives. So when you run an app like Tomboy, it loads its libraries such as GTK# from the GAC belonging to the Mono runtime being used. Ordinarily, this is in /usr/lib/mono/gac on a Debian/Ubuntu system.

When you have your parallel Mono, it doesn’t share a GAC – as a result, libraries in your main distro GAC are not available in your DIY GAC, as they were never registered in there.

Typically, the advice is to either start compiling every lib you need into a non-standard place too – however, here’s a better idea. Why not make Apt take care of not only your system’s GAC – but additional GACs too? We actually have structures in place to handle this, so it’s not as hard as you think (merely relatively unknown). This guide does NOT take startup scripts into account – it’s your problem to ensure you’re using the correct “mono” command to run your copy of MonoDevelop or Tomboy or whatever. You should probably learn about update-alternatives and $PATH for this. Oh, and this guide will BREAK HORRIBLY if you try to uninstall system mono completely. Don’t try it.

Setup step 1: preparation
Don’t install parallel Mono into /usr/local. I don’t care what happens to you if you do. Use some random folder in /opt, usually a per-build prefix like /opt/mono-2.10

Setup step 2: duplicating existing magic
Open a terminal, and copy /usr/share/cli-common/runtimes.d/mono to a new filename, e.g. /usr/share/cli-common/runtimes.d/mono-2.10

Setup step 3: tweak duplicate magic
Open your copied file in an editor, and change the name value on line 27ish (e.g. from “Mono\n” to “Mono (parallel 2.10 install)\n”). Then change the two places in the file, on lines 64ish and 120ish, from “/usr/bin/gacutil” to “/opt/mono-2.8.2/bin/gacutil” or equivalent.

Setup step 4: apply magic to existing packages
Run “/usr/share/cli-common/gac-install mono-2.10″ (or whatever filename you picked for your runtimes.d entry) as root. This will instantiate your parallel GAC(s).
From now on, every GAC library you install or uninstall will happen to every single runtime in runtimes.d.

To go back to how things were before, with only a single Mono runtime:

Read more: ApeBox