Compiling Mono from source

Compiling Mono can be a pain in the backside at times, but is actually worth the time taken. Okay, you're on the edge if you compile via svn, but it's your choice...


This page has been re-written to reflect the change at Novell from using CVS to using subversion (svn). svn is available from the subversion website

What you need

You will need the following tools to install Mono

I have written a second page on compiling from the tarballs. The instructions are generic of either the unstable or the real release versions

Got those? Good. Let's start. If you have never installed Mono before in either source or binary form, you can ignore the next bit (go to the svn bit!). For those who have, it's important to hose it from your system. As I don't have a clue where Mono is installed under Windows, I'll leave you to find that. If you do know, please email me with details on where in your system Mono is and I'll include it on here. I would imagine that some of it would be inside of "Programs" with the dlls inside of the Windows directory

Okay, not a problem... First off, open a terminal window and type

rpm -qa mono-*

This will give you a list of all of the mono components installed. It won't tell you if you have gtk-sharp installed (or any other mono components), but you'll find them quickly enough. If nothing shows, you don't have them installed as RPMs. For Debian & Mac users, please see beneath the rpm instructions.

Next thing you need to do is remove them! Below is the list if you have *everything* installed.

rpm -e mono-ms-extras mono-core-devel mono-locale-other mono-complete mono-remoting 
mono-peapi mono-data-postgresql mono-ziplib mono-posix mono-locale-mideast mono-data-sqlite
mono-cairo mono-web-services mono-novell-directory mono-drawing mono-data mono-winforms
mono-nunit mono-ikvm mono-data-oracle mono-runtime-devel mono-ms-enterprise mono-directory
mono-core mono-web-forms mono-preview mono-locale-rare mono-complete-devel mono-xml-relaxng
mono-locale-cjk mono-basic monodoc gtk-sharp xsp monodevelop gtksourceview-sharp ibm-data-db2
ikvm gtk-sharp-gapi gecko-sharp bytefx-data-mysql mono-data-sybase cairo cairo-devel 
libpixman libpixman-devel

Note for Debian users

The following information has been supplied to me by John Lenz via the mono-list mailing list

In debian, the command

dpkg -l mono*

will give a list of all mono components available in debian (well, all that start with mono), and the first column will say if the pacakge is installed or not. For example, a section of the output on my computer looks like:

ii  mono-common    1.0.2-1        common files for the Mono CLI runtimes
ii  mono-jit       1.0.2-1        fast CLI (.NET/Mono) JIT compiler
ii  mono-mcs       1.0.2-1        the Mono C# compiler
un  mono-mint      <none>         (no description available)
ii  mono-utils     1.0.2-1        Mono utilities

dpkg --purge <list of packagenames> 

is used to purge packages (which means remove everything, including config files that might have been created). This must be run as root, where the dpkg -l can be run as any user...

Note for Mac users

The following came through to me via email from Martin Otten

You asked in your mono-compiling-tutorial for the location of mono on 
mac os.

It depends on how you installed Mono. If you have done it using fink you 
do:  "fink remove mono" this would remove if no other packages depend on it.

If you installed the dmg you have to remove 

If your system doesn't have one (or more) of those packages, remove them from the above list and try again.

First off, you need to know where it is installed to. If you haven't specified anything when you installed the code originally, then you should get the same as below

which mono

As long as when you compile Mono you specify to use /usr/local as the root of the install directory, you shouldn't have a problem with conflicting libraries

Compiling from svn

Step one is to download the source code. Open a terminal window and

svn co svn://<module name>

or alternatively, download this script which will grab the sources for you.

Note about the script. The script now performs a number of tasks. It will check if you have the mono directories on your system and if you have, it will update rather than checkout from svn. After that, it will compile the code for you. If you have yourself set as sudo, please alter the script and let it run automatically. This should now allow things to be set as a cron job.

<module name> is the name of the module you want to grab. At a minimum, that should be mono, mcs, gtk-sharp. You will need to issue the svn command line for each module. You can download everything though by leaving off the <module name>

Modules available

  • appserver
  • cocoa-sharp
  • csvorbis
  • dbus-sharp
  • debugger
  • diacanvas-sharp
  • ginzu
  • glgen
  • gsf-sharp
  • gst-sharp
  • gtk-sharp
  • gtkmozembed-sharp
  • gtksourceview-sharp
  • guile-mono
  • janet
  • lb
  • lcc
  • libgdiplus
  • mbuild
  • mcc
  • mcs
  • mod_mono
  • monkeyguide
  • mono
  • mono-tools
  • monocov
  • monodoc
  • monologue
  • monotalk
  • mphoto
  • mwn
  • nunit-gtk
  • objc-sharp
  • sqlsharpgtk
  • svn-tools
  • tao
  • tsunami-bindings
  • winelib
  • winforms
  • xsp

To update your copy of mono, you just need to issue the same svn command as was used to download the source.

Cairo and libpixman are both required. You'll need it if you want to using the System.Drawing classes. They are now included in libgdiplus

If you don't want the library to go into /usr/local/lib, then instead of saying ./, you type ./ --prefix=/usr. This applies for everything in these instructions

Once the sourcecode has downloaded (you'll probably need to go the loo as well, the coffee cup may need a wash as well. Hmm, I think the dog needs to go out...), the install can go ahead. In a terminal window (and if you want or need to, ignore anything in brackets - it's an option)...

cd libgdiplus
./ (./ --prefix=/usr)
make install
/sbin/ldconfig (see "Making sure gdiplus is found" below)
exit (takes you back to a normal user)
cd ../mono
./ (--prefix=/usr) --with-preview= {yes/no} (see below)
make get-monolite-latest
make install
cd ../gtk-sharp
./bootstrap (-2.4 --prefix=/usr) (see below)
make install
cd ../monodoc
./ (--prefix=/usr)
make install

Building gtk-sharp

The build process for gtk-sharp is different to the other modules in mono. Instead of ./, there is the choice of ./bootstrap and ./bootstrap-2.4. The only difference is if you're using the bleeding edge version, you should use the 2.4 version.

As before, passing --prefix=/usr on the command line will install to /usr rather than /usr/local.

Making sure gdiplus is found

You will need to make sure that the libgdiplus can be accessed; otherwise you will get an error about not being able to find gdiplus.dll. There are two possible solutions you can use.

If you have a file /etc/ and it contains a line /usr/local/lib (or /usr/lib if you specified --prefix=/usr) then running /sbin/ldconfig will reload the cache and pick up the libgdiplus that you just installed. If it is not there then you could add it and run ldconfig. You only need to run ldconfig after reinstalling libgdiplus (using make install).

Alternatively you can ensure that the environmental variable LD_LIBRARY_PATH contains /usr/local/lib (or /usr/lib if you specified --prefix=/usr) whenever you run mono.

I must thank Bill Medland for pointing this out to me.

What's this --with-preview about?

If you want the newest parts, you should specify --with-preview=yes. Otherwise, either leave the line out or say --with-preview=no.

Once that has all been done, you now have a basic working system with everything you will need to compile a C# program or create a GTK application using C# instead of C or C++.

Having problems with the libraries being out of sync?

One of the most annoying problems you may find when changing from the tarballs, or if you're rolling your own for the first time or it's been a while since you last did an update is that you'll find get an error about your libraries and run-time being out of sync.

To get around this...

tar -zxf monocharge-<version>
cd monocharge-<version>
(env prefix=/<wherever>) ./

(env prefix=) is not required if you're installing to /usr/local/. If you are compiling to anywhere other than that, you will need to define it like this env prefix=/usr ./ This should be enough to fix the problem. Using monolite will not fix the problem.

I compiled using --with-preview=yes

Well done! You have compiled the preview code which will be in the 1.2 release (this was due at the end of 2004, but it looks like that has been delayed). Please remember that this code is really alpha in quality, but should be okay to use

Updating from svn

svn co svn://<module name>

You can now go to the mono directory...

make bootstrap
make install

You should then recompile libgdiplus, xsp, monodoc and any other component which has been updated

Installing monodevelop

You will need to grab a copy of gecko-sharp from - the current version is 0.5. Dearchive, compile and install. It is available via svn as well (you can just alter my download script to include this).

Installing monodevelop ( can be done by either downloading the tarball and following the instructions on their website, or by downloading the source via svn (this is similar to cvs, but you will need a client for your system).

Downloading via svn

svn co svn://
cd MonoDevelop
./ (--prefix=/usr)
make install

MonoDevelop is mirrored at svn://

Paul's monoupdater script

This is a very small shell script which has been developed (if you can call it that!) for a while now to save me masses of time. It has 4 main functions now which are passed on the command line

./ help

monoupdater script. (c) 2004-2005 Paul F. Johnson
Released under the GPL Vsn 2

Usage: < options >
options:   clean - performs a make clean before building
         rebuild - performs a make distclean before building
           build - performs a make without checkout
            help - displays this message
                 - performs a checkout and make

I intend adding a makerpm at some point as well as an option for making a distributable version for debian and other platforms. The problem here though is that different distros use different spec files for building, so it may have to be makerpm fc|mandriva|suse|debian (as well as makepkg osx|win32.

Downloading the script

You can get it here while it's hot!