Install Mono 2.4 on Ubuntu

In: Mono|Ubuntu

12 Jun 2010

Compiling and installing the latest release of Mono (version 2.4 at time of writing) on Ubuntu is not as hard as it sounds, these instructions should also work on newer versions of Mono.

IMPORTANT: If you’re installing on a VPS, make sure that you have at least 128 MB of RAM available, or otherwise the mono compilation process will fail.

WARNING

Following these instructions will result in all your pre-installed Mono applications being removed from your Ubuntu box. In most cases the only way to get them back is going to be by installing them from source too (not always a bad idea).

Installing Mono

Open a terminal window if you’re using the Ubuntu GUI or log on using SSH if you’re accessing a remote server.

All these instructions assume that you have root privileges, so if you’re not logged in as root, enter the following and enter you password when prompted.

$ sudo bash

First you need to remove the version of Mono that is pre-installed with Ubuntu.

$ apt-get remove mono-common

That will remove all the extra packages that are installed with mono as they all depend on it. Be aware that it will also remove applications like f-spot and beagle, which will have to be re-installed after the mono upgrade if you wish to use them.

Next, create a folder for the source code you’re about to compile:

$ mkdir /src

Then change to the src directory:

$ cd /src

Make sure that your /etc/apt/sources.list file has the universe and multiverse repositories included. If you installation didn’t have any internet connectivity, there may be a chance that the installer disabled those repositories due to being unable to verify them. If that is the case, do the following:

$ vi /etc/apt/sources.list

Refresh the apt-get database.

$ apt-get update

You now need to install some Mono build dependencies (and some optional enhancements):

$ apt-get install build-essential pkg-config libglib2.0-dev bison libcairo2-dev libungif4-dev libjpeg62-dev libtiff4-dev gettext

Download libgdiplus:

$ wget http://ftp.novell.com/pub/mono/sources/libgdiplus/libgdiplus-2.4.tar.bz2
$ tar -xvf libgdiplus-2.4.tar.bz2
$ cd libgdiplus-2.4/

Now we can compile libgdiplus and install it:

$ ./configure –prefix=/usr/local; make; make install

Now go make yourself a snack, especially if you’re doing this on a Virtual Machine  😀

After the compilation finally finishes, we need to make sure the new packages are visible to the system:

$ sh -c “echo /usr/local/lib >> /etc/ld.so.conf”
$ /sbin/ldconfig

Now change back to the /src folder and download the latest release of mono (about 17 MB):

$ cd /src
$ wget http://ftp.novell.com/pub/mono/sources/mono/mono-2.4.tar.bz2

Extract the compressed file, change into the mono folder and compile:

$ tar -xvf mono-2.4.tar.bz2
$ cd mono-2.4
$ ./configure –prefix=/usr/local; make; make install

You can go make yourself a gourmet meal at this point as the compilation process takes a seriously long time (ok, maybe not that long, but us generation X/Y types don’t really have the patience for C++ compilation).

Add mono to the bash path:

$ vi ~/.bashrc

And add the following lines at the end:

PATH=/usr/local/bin:$PATH
LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

In order for the changes to take effect, you need to either close and open your terminal again, or simply type:

$ bash

to start a new instance of bash command line.

To check your new mono version, type:

$ mono -V

You should see the following:

Mono JIT compiler version 2.4 (tarball Wed Apr 1 04:49:16 CDT 2009)
Copyright (C) 2002-2008 Novell, Inc and Contributors. www.mono-project.com
TLS: __thread
GC: Included Boehm (with typed GC)
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none

Congratulations, you have a working copy of the latest Mono released installed on your Ubuntu machine!

Installing XSP

XSP is the Mono web server that Apache delegates to (via mod_mono) when serving ASP.NET pages on Linux. In order to run ASP.NET pages you will need to compile and build the XSP web server.

Change to your /src directory, download the XSP sources, unzip them and compile:

$ cd /src
$ wget http://ftp.novell.com/pub/mono/sources/xsp/xsp-2.4.tar.bz2
$ tar -xvf xsp-2.4.tar.bz2
$ cd xsp-2.4/
$ ./configure –prefix=/usr/local; make; make install

Once the compilation is done, we can test the XSP server. Change to the XSP test installation folder and run the XSP server:

$ cd /usr/local/lib/xsp/test
$ xsp2

You should see something like the following:

xsp2
Listening on address: 0.0.0.0
Root directory: /root
Listening on port: 8080 (non-secure)
Hit Return to stop the server.

Open your browser and point it to http://localhost:8080 (or your domain/ip if you’re doing this remotely). You should see the XSP test page.

Installing Mod_Mono

Mod_mono is the name of the apache2 module that links the XSP server and apache. This allows for apache to handle all incoming requests and hand them off to the XSP process in order to server your ASP.NET pages. You only need to install Mod_mono if you plan on using Apache2 to serve web pages. You will also need to have apache2 (and it’s development files) pre-installed to compile mod_mono.

Install apache2 and the necessary build dependencies:

$ apt-get install apache2 apache2-threaded-dev

Once that’s done, we can compile mod_mono.

Change to our source directory, download the mod_mono sources, unzip them and compile:

$ cd /src
$ wget http://ftp.novell.com/pub/mono/sources/mod_mono/mod_mono-2.4.tar.bz2
$ tar -xvf mod_mono-2.4.tar.bz2
$ cd mod_mono-2.4/
$ ./configure –prefix=/usr/local; make; make install

We need to include the mod_mono.conf file in the apache2 configuration file, so open the apache2.conf file in a text editor:

$ vi /etc/apache2/apache2.conf

Scroll to the bottom of the file and include the following line:

Include /etc/apache2/mod_mono.conf

Now lets copy the test content from XSP to our apache2 public folder to we can have an ASP.NET application with which to test the mod_mono installation:

$ cp -r /usr/local/lib/xsp/test /var/www/test

When you compile Mod_mono from source, the necessary apache2 configuration files are not created for you, so we will have to do them manually.

Firstly, create the mod_mono.load file with a text editor:

$ vi /etc/apache2/mods-available/mod_mono.load

Add the following line to the file:

LoadModule mono_module /usr/lib/apache2/modules/mod_mono.so

Next we create the mod_mono.conf file:

$ vi /etc/apache2/mods-available/mod_mono.conf

Add the following to the file:

AddType application/x-asp-net .aspx .ashx .asmx .ascx .asax .config .ascx
DirectoryIndex index.aspx
include /usr/local/lib/mono/2.0/mono-server2-hosts.conf

Next, create the mono-server2-hosts.conf file:

$ vi /usr/local/lib/mono/2.0/mono-server2-hosts.conf

And add the following:

<IfModule mod_mono.c>
MonoUnixSocket /tmp/.mod_mono_server2
MonoServerPath /usr/local/lib/mono/2.0/mod-mono-server2.exe
AddType application/x-asp-net .aspx .ashx .asmx .ascx .asax .config .ascx
MonoApplicationsConfigDir /usr/local/lib/mono/2.0
MonoPath /usr/local/lib/mono/2.0:/usr/local/lib
</IfModule>

Configure Apache2 Virtual Hosts

The virtual hosts configuration really requires a tutorial on its own, but for now I’ll just show you how to make the test application the default site on your apache2 server.

Edit the default virtual host file for apache2:

$ vi /etc/apache2/sites-enabled/000-default

Replace the contents of the file with the following (you may want to backup the file first):

<VirtualHost *>
ServerName www.local.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/test
DirectoryIndex index.html index.aspx
MonoDocumentRootDir “/var/www/test”
MonoServerPath rootsite “/usr/local/bin/mod-mono-server2”
MonoApplications rootsite “/:/var/www/test”

<Directory /var/www/test>
MonoSetServerAlias rootsite
SetHandler mono
AddHandler mod_mono .aspx .ascx .asax .ashx .config .cs .asmx
</Directory>

</VirtualHost>

Now restart apache2:

$ /etc/init.d/apache2 restart

Now open your browser and navigate to http://localhost/. You should see the XSP test web app appear.

Restart Errors

When you restart apache2 using the command above, you are likely to see an error message similar to the following:

* Restarting web server apache2
[Fri Nov 06 00:41:41 2009] [crit] (13)Permission denied: Failed to attach to existing dashboard, and removing dashboard file ‘/tmp/mod_mono_dashboard_XXGLOBAL_1’ failed (Operation not permitted). Further action impossible.

This is quite normal and will not affect the operation of your Mono websites.

References:


2 Responses to Install Mono 2.4 on Ubuntu

Avatar

Rob

June 13th, 2010 at 8:08 pm

Ta. Installed ubuntu on a spare pc today. this will come in handy.

Avatar

Installing Mono on Ubuntu - JUSTINSHIELD.COM

May 12th, 2011 at 10:53 am

[…] You will still need to configure apache2, so use the rest of the instructions on this page: Install Mono 2.4 on Ubuntu […]

Comment Form

About Justin

justin

Justin is a Senior Software Engineer living in Brisbane. A Polyglot Developer proficient in multiple programming languages including [C#, C/C++, Java, Android, Ruby..]. He's currently taking an active interest in Teaching Kids to Code, Functional Programming, Robotics, 3D Printers, RC Quad-Copters and Augmented Reality.

About This Blog

Software Engineering is an art form, a tricky art form that takes as much raw talent as it does technical know how. I'll be posting articles on professional tips and tricks, dos and donts, and tutorials.

profile for Justin Shield on Stack Exchange, a network of free, community-driven Q&A sites

Photostream

  • What I look for in a senior software engineer Justin Shield: […] I’m not going to list the design patterns that you’ll need, I’ve already [...]
  • Justin: Hi Ross, I do actually like Umbraco, it provides some nice abilities for creating websites that I [...]
  • Justin: Hi GordonBGood, Thanks for taking the time in replying. You're absolutely correct, it is turners s [...]
  • Ross Gallagher: Hi Justin, I'm a fellow Aussi looking to use Umbraco to create a simple website. I have downloaded [...]
  • GordonBGood: This is the "Turner Sieve" which **IS NOT** the Sieve of Eratosthenes (SoE) neither by algorithm nor [...]