Ubuntu ships with Mono pre-installed, but due to the rapid release cycles on the Mono project, the version that ships with Ubuntu is often outdated by the time the Ubuntu release ships. Due to the impressive release schedule of Mono, you do really need to keep up with the new releases as every new release dramatically improves the entire framework.
Unfortunately for Ubuntu users, there are no dedicated Ubuntu packages for download from the Mono Project web site, which means that you best bet is be to compile the project yourself. While I know that most Linux newbies find that concept intimidating, it actually isn't nearly as hard as it sounds.
To that end, I'll walk you through compiling and installing the latest release of Mono (version 2.4 at time of writing) on Ubuntu. Note that these instructions should also work on newer versions of Mono.
These instructions were created by installing Mono 2.4 on an absolutely fresh installation of Ubuntu. For those Windows users wishing to try this out at home, I would suggest installing Ubuntu on a Virtual PC 2007 virtual machine. Arcanecode has an excellent post on getting this to work first time.
IMPORTANT: If you're installing on a VPS, make sure that you have at least 400 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).
If you'd like to play with Mono 2.4, but keep things like F-Spot and Beagle, I would suggest rather using the instructions provided by Jan Dzik.
Update: I now have a script that automates the install, see this post: Mono Compile & Install Script
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:
$ nano /etc/apt/sources.list
Remove the # characters from the universe and multiverse entries and save the file (a Nano Basics Guide is available for
people new to nano). I personally just enable everything.
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 VM :P
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:
$ nano ~/.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:
xsp2Listening on address: 0.0.0.0Root directory: /rootListening 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:
$ nano /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:
$ nano /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:
$ nano /etc/apache2/mods-available/mod_mono.conf
Add the following to the file:
AddType application/x-asp-net .aspx .ashx .asmx .ascx .asax .config .ascxDirectoryIndex index.aspxinclude /usr/local/lib/mono/2.0/mono-server2-hosts.conf
Next, create the mono-server2-hosts.conf file:
$ nano /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:
$ nano /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:
