Parallel Mono Environments

From Mono

This document details how to run multiple Mono environments on a single system where neither environment conflicts with another.

This assumes that you are familiar with the compilation process for Mono.

Table of contents

What's the Point?

It may be desirable to have two or more completely separate and independent Mono stacks running at the same time, for development purposes or even for running unstable applications without compromising existing installed stable versions.

For example, under SUSE 10 Mono, Banshee, F-Spot, and Tomboy (to name a few) are all installed by default, are considered "stable," and are linked against "stable" Mono libraries, such as gtk-sharp-2.x.

It is possible to run the latest versions of these applications (for example, from Mono SVN) with the latest version of Mono by installing all components into a separate prefix with different environment variables.

Getting Sources

This document assumes that a distribution-installed Mono environment already exists, and is installed in a prefix other than /opt/mono.

The "parallel" environment this document details is installed from either source tarballs or from Mono SVN.

Source Tarballs

First, download the Released Source Mono Tarballs (http://go-mono.com/sources-stable/). This document is concerned only with mono, libgdiplus, gtk-sharp-1.x, gtk-sharp-2.x, monodoc, and mono-tools.

Source from Version Control (Mono SVN)

Modules in Mono SVN (http://svn.myrealbox.com/) correspond to the source tarballs above. Respective modules are: mono, mcs, libgdiplus, gtk-sharp, and monodoc. If you are using SVN rather than released tarballs, you must run the ./autogen.sh script to generate the autotools build system before you will be able to run ./configure commands.

Seting up a Build Environment

To prevent introducing elements from the existing Mono environment, a new environment must be set up. This section assumes GNOME is installed in /opt/gnome.

Create a bash script named something like ~/mono-dev-env. Its contents should be similar to the following:

#!/bin/bash
MONO_PREFIX=/opt/mono
GNOME_PREFIX=/opt/gnome
export LD_LIBRARY_PATH=$MONO_PREFIX/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=$MONO_PREFIX/include:$GNOME_PREFIX/include
export ACLOCAL_PATH=$MONO_PREFIX/share/aclocal
export PKG_CONFIG_PATH=$MONO_PREFIX/lib/pkgconfig:$GNOME_PREFIX/lib/pkgconfig
PATH=$MONO_PREFIX/bin:$PATH
PS1="[mono] \w @ "

Along with setting appropriate environment variables to only use sources from /opt/mono and /opt/gnome, it also sets the Bash prompt to something other than the default, so it is easy to detect when Bash is in this alternate environment.

Finally, to enter this environment at any time, run the following from a Bash prompt:

source ~/mono-dev-env

Once in the environment, sources can be built and installed.

Tip: Your first build

Your first build will take place from the "mono" directory, that will do an initial build. Make sure that you "make install" after you are done, and you make sure that the new "mono" is in your path.

You can do this by running "mono --version", and it should hopefully be a different version than what you have installed, or you can use the command "which mono", and it should point to the mono version in the prefix you have chosen.

Tip: Rebuilding Class Library Parts

It is not necessary to rebuild the entire Mono every time you make a change in a class library. For example, if you just updated something in mcs/class/System.Web, do this:

cd mcs/class/System.Web
make && make install

That will build and install only that directory.

In addition, if you are developing code for the 2.0 API, you must instruct make to build and install 2.0 components, so that looks like this:

cd mcs/class/System.Web
make PROFILE=net_2_0 && make install PROFILE=net_2_0

Tip: CONFIG_SITE

Try adding this to the script:

export CONFIG_SITE="$HOME/.config/automake/config.site"

and in that file writing:

test "$prefix" = NONE && prefix=/opt/mono

This will let you avoid typing --prefix all the time

Tip: MONO_GAC_PREFIX

MONO_GAC_PREFIX is a colon-separated list of prefixes that should be searched for GAC directories. It is particularly useful for using your OS-provided GAC within your parallel environment.

For example, if I have Gtk# 1.0.x installed as part of my primary environment under /usr/lib/mono/gac/gtk-sharp and you want to build Gtk# 1.0 applications using your parallel environment under /opt/mono. There are two ways to do this:

  1. Build Gtk# 1.0.x yourself and install it with the prefix $MONO_PREFIX.
  2. export MONO_GAC_PREFIX=/usr. This will allow your parallel environment to find the Gtk# 1.0 libraries provided by your distribution.

Building Sources

This section details only building from released source tarballs. Building from checked-out Mono SVN sources is similar. These instructions are based on the Mono 1.1.9.1 release. Subsequent releases should have similar build procedures, but tarball file names will change.

Enter the alternate mono environment as outlined in the previous section:

source ~/mono-dev-env

libgdiplus

Ensure you have all development packages installed for TIFF, PNG, GIF, and JPEG libraries before configuring.

tar zxf libgdiplus-1.1.9.1.tar.gz
cd libgdiplus-1.1.9.1
./configure --prefix=/opt/mono
make
sudo make install

mono

Under SUSE 10, compilation may fail. See the fix related to the VER_1 (http://lists.ximian.com/pipermail/mono-list/2005-October/028833.html) ld build error.

tar zxf mono-1.1.9.1.tar.gz
cd mono-1.1.9.1
./configure --prefix=/opt/mono
make
sudo make install

gtk-sharp

tar zxf gtk-sharp-1.0.10.tar.gz
cd gtk-sharp-1.0.10
./configure --prefix=/opt/mono
make
sudo make install

Note: make may fail the first time here, for some unknown reason, running make a second time works.

gtk-sharp-2

tar zxf gtk-sharp-2.3.91.tar.gz
cd gtk-sharp-2.3.91
./configure --prefix=/opt/mono
make
sudo make install

Note: make may fail the first time here, for some unknown reason, running make a second time works.

monodoc

tar zxf monodoc-1.1.9.tar.gz
cd monodoc-1.1.9
./configure --prefix=/opt/mono
make
sudo make install

mono-tools

tar zxvf mono-tools-1.1.9.tar.gz
cd mono-tools-1.1.9
./configure --prefix=/opt/mono
make
sudo make install

Conclusion

A fully independent Mono environment should now be available in /opt/mono.

Common Problems

Sometimes, the wrapper shell scripts for system installed programs to not write out the full path to mono. For example, while in this new environment, you might execute /usr/bin/monodevelop. Sometimes, this results in the new mono being used. If this is the case, you should report a bug to the developer. Likewise, even if you specify a path like /opt/mono/bin/monodevelop, the old mono may be used.

Read also How not to break Mono installations (http://mjhutchinson.com/journal/2007/11/08/how_not_break_mono) (this info should be merged with this article or included in this wiki).