Installing Mono

Obtaining Mono

There are several ways to get Mono running on your computer. This document will discuss only one of those: downloading the source tarball and utilising the make utilities to get mono up and running. There is only one mono package to worry about if you are just after a 'base' install of mono: the mono runtime. This package, found under the name "mono-x.xx" has got a compiled version of the compiler built in.

You'll be able to complete everything in this document if you just install the runtime, but taking a look at the compiler package is well worth the effort. The compiler is written in C# and is 'self hosting' which means it is able to compile itself.

As of this moment, it is my understanding that there are still some issues with the 'self hosting' bit of the compiler on linux, although this is expected to work in later versions of mono. If you are just interested in finding out how mono will work under linux, I would not worry about the self-hosting bit for now. The self-hosting of the compiler will be the topic of a future howto.

See the mono download site for the source of the tarballs.

This page also lists the current versions of the software mono depends on. Make sure that your system has all the required versions, otherwise mono won't compile.

At a minimum for mono 0.12, you'll need to:

Installing the tarballs is done via GNU autoconf and automake. The general upshot of running autoconf and automake is that you can type ./configure and then make to do the build. Typing make install completes the installation of mono on your system.

To build the mono runtime package, unzip the tarball to some useful location. I tend to use /usr/src as the location, but you could really do it anywhere. For the install process, it is also a good idea to be 'root'. The installation process will shuttle some executables into /usr/local/bin (more about that later).

Unzipping the tarballs will have created two directories in /usr/src/, one called something like mono-x.xx and the other mcs-x.xx. The one called 'mono' is the runtime environment, and this contains all that is initially needed to run mono and investigate its inner workings.

To start building the mono runtime, first type ./configure. You will see an output like this:


[root@taurus mono-0.12]# ./configure
loading cache ./config.cache
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking build system type... i686-pc-linux-gnu
checking for a BSD compatible install... (cached) /usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets ${MAKE}... (cached) yes
checking for working aclocal... found


snip ....


checking BASE_DEPENDENCIES_CFLAGS...  -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
checking BASE_DEPENDENCIES_LIBS...  -lglib-2.0
checking for GC_malloc in -lgc... (cached) no
configure: warning: Compiling mono without GC.
checking if off_t is 64 bits wide... no
checking if _FILE_OFFSET_BITS=64 gives 64 bit off_t... ok

snip ...

creating Makefile
creating mono/Makefile
creating mono/utils/Makefile
creating mono/metadata/Makefile
creating mono/dis/Makefile
creating mono/cil/Makefile
creating mono/arch/Makefile
creating mono/os/Makefile
creating mono/os/win32/Makefile
creating mono/os/unix/Makefile
creating mono/arch/x86/Makefile
creating mono/arch/ppc/Makefile
creating mono/arch/sparc/Makefile
creating mono/arch/arm/Makefile
creating mono/interpreter/Makefile
creating mono/tests/Makefile
creating mono/benchmark/Makefile
creating mono/monoburg/Makefile
creating mono/monograph/Makefile
creating mono/jit/Makefile
creating mono/io-layer/Makefile
creating mono/handles/Makefile
creating runtime/Makefile
creating scripts/Makefile
creating man/Makefile
creating doc/Makefile
creating docs/Makefile
creating config.h
config.h is unchanged


        GC:     auto


[root@taurus mono-0.12]#

This means that the configure script has now created all the makefiles necessary to complete the build on your system. Note the "GC: auto" at the end of the list of commands. GC stands for "garbage collection" and it will be addressed in a later section of this document.

You are now ready to start the mono "build" process. To kick this off, you can type make at the command prompt. You'll see something like this:


[root@taurus mono-0.12]# make
make  all-recursive
make[1]: Entering directory `/usr/src/mono-0.12'
Making all in mono
make[2]: Entering directory `/usr/src/mono-0.12/mono'
Making all in utils
make[3]: Entering directory `/usr/src/mono-0.12/mono/utils'
gcc -DHAVE_CONFIG_H -I. -I. -I../.. -I/usr/include/glib-2.0 
-I/usr/lib/glib-2.0/include   -I/usr/include/glib-2.0 
-I/usr/lib/glib-2.0/include   -I../.. -I../../mono   
-D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE   -g -Wall 
-Wunused -Wmissing-prototypes -Wmissing-declarations 
-Wstrict-prototypes  -Wmissing-prototypes -Wnested-externs 
-Wpointer-arith -Wno-cast-qual -Wcast-align -Wwrite-strings 
-c mono-hash.c

and this will continue for a while. On my 1 GHz Duron with 256 MB of RAM the total build process takes about three minutes. All the terrible flags after gcc have essentially been set by the configure script and there is no need to worry about these.

To finally install mono, you can type make install to get a working version of mono. This command will copy the scripts that run the executables to a place where the operating system will be ale to find them. This location is /usr/local/bin on my system.

Garbage Collection

To make the mint interpreter work with garbage collection, you first need to install a garbage collection package on your system. Mono works with Boehm Garbage collection, which is found at http://www.hpl.hp.com/personal/Hans_Boehm/gc/ .

To get garbage collection to work, I downloaded the source tarball into /usr/src/ and typed ./configure followed by make and make install.

There is one glitch to work around. The header file for the garbage collection gc.h is found in the /usr/src/gc6.0/include directory (at least on my system). The mono build process will break on this location: it is looking for the header file in some other place called /usr/include/gc/ and won't be able to find the correct header file.

The solution is to build a symbolic link between these two locations as follows


[root@taurus include]# ln -s /usr/src/gc6.0/include/ /usr/include/gc

after which you'll be able to list the directory contents as if they were in /usr/include


[root@taurus include]# pwd
/usr/include
[root@taurus include]# ls /usr/include/gc
cord.h                gc_backptr.h  gc_inline.h             javaxfc.h
ec.h                  gc_cpp.h      gc_local_alloc.h        leak_detector.h
gc                    gc_gcj.h      gc_mark.h               new_gc_alloc.h
gc_alloc.h            gc.h          gc_pthread_redirects.h  private
gc_amiga_redirects.h  gc_inl.h      gc_typed.h              weakpointer.h
[root@taurus include]#

To get mono to work with garbage collection, you'll have to rebuild the environment. This is done easily by typing make distclean to clean up any existing executables.

Continue the build by typing ./configure, and look at the last line. It should read:


snip...

creating config.h


        GC:     boehm


[root@taurus mono-0.12]#

The GC: boehm tells you that garbage collection has been turned on. Now to compile the runtime, you type make and make install as previously.

You now have mono working with Garbage Collection.

Although my experimentation is incomplete as of this time, I have found some issues with running Garbage Collection continuously, and my recommendation would be to turn it off for now.

To turn garbage collection off again, you have to go to the /usr/src directory where you extracted the tarball. Enter the gc6.0 directory and type make uninstall to uninstall Garbage Collection. Then in your mono directory, type make distclean followed by ./configure, make and make install.