Compiling Mono on OSX

Pick an installation directory where you want your new copy of Mono to be installed. Lets call that location DIR. Your Mono installation and its dependencies will be installed there. For example, I like to use the directory /mono, so I would replace DIR with /mono in the following discussion.

If you have more than one Mono installation (for example to keep multiple versions around), you will want to read the document on Parallel Mono Environments on how to keep your various Mono installations separate.

It is strongly advised not to install Mono from source in /usr, /usr/local or any other "standard" directories unless you know what you are doing.

Downloading and Installing Dependencies

To build Mono, you will need to install a number of dependencies that are usually part of a standard Linux distribution, but are not part of MacOS X.

Obtain the following software:

  • GNU gettext download (ftp://ftp.gnu.org/pub/gnu/gettext)

Setting up your Environment

You will want to make sure that the following environment variables are set before starting your build. Set these from the shell, or in a script,

MONO_PREFIX=DIR
export DYLD_LIBRARY_PATH=$MONO_PREFIX/lib:$DYLD_LIBRARY_PATH
export C_INCLUDE_PATH=$MONO_PREFIX/include:$C_INCLUDE_PATH
export ACLOCAL_PATH=$MONO_PREFIX/share/aclocal
export ACLOCAL_FLAGS="-I $ACLOCAL_PATH"
export PKG_CONFIG_PATH=$MONO_PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH
PATH=$MONO_PREFIX/bin:$PATH
PS1="[mono] \w @ "

You can either type those in the shell, or put in a file that you then have to 'source', to source it you would save that file in ~/bin/setup-mono for example, and then issue this command:

   $ source ~/bin/setup-mono

This has to be sourced as opposed to executed, because if you merely execute it as a shell script, the settings only occur on a new instance of the shell. The source command makes sure that all the settings happen in your current active shell.

Building GNU Gettext

This library is a requirement to build glib and pkg-config, it provides support for adding international support to applications. It is an indirect requirement.

Go into the shell, and unpack the downloaded package. When you configure it, remember to replace the word DIR here with the location that you picked for installation:

   $ tar xvf gettext-0.17.tar
   $ cd gettext-0.17
   $ ./configure --prefix=$MONO_PREFIX
   $ make 
   $ make install

Building pkg-config

Go into the shell, and unpack the downloaded package. When you configure it, remember to replace the word DIR here with the location that you picked for installation:

   $ tar xvf pkg-config-0.23.tar
   $ cd pkg-config-0.23
   $ ./configure --prefix=$MONO_PREFIX
   $ make 
   $ make install

Building glib


Go into the shell, and unpack the downloaded package. When you configure it, remember to replace the word DIR here with the location that you picked for installation.

Also notice that we pass the variable CC="cc -LDIR" in the command line so that glib can detect properly the previously installed gettext:

   $ tar xvf glib-2.18.2
   $ cd glib-2.18.2
   $ CC="cc -L$MONO_PREFIX/lib" ./configure --prefix=$MONO_PREFIX
   $ make 
   $ make install

Building the Mono Components

Once you have all the dependencies compiled you are now ready to build Mono from either SVN or from a tar.gz package.

The process here is identical to the process described in the rest of this document, if you are using a tarball distribution do:

  $ tar xvf mono-2.0.1.tar.gz
  $ cd mono-2.0.1
  $ ./configure --prefix=DIR
  $ make
  $ make install

If you are using an SVN checkout of Mono, you will need to have an existing Mono installation installed (as you will need a C# compiler to bootstrap).