peteris.rocks

Mono Installation on Ubuntu Server

How to set up mono on Ubuntu Server from official packages, source tarball or GitHub

Last updated on

Run C#/.NET applications on Linux.

Install from packages

This works on Ubuntu 14.04 LTS and later. These are the official packages. This is the recommended way to install mono.

curl -s http://download.mono-project.com/repo/xamarin.gpg | sudo apt-key add -
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/xamarin.list
sudo apt-get update
sudo apt-get -y install mono-complete

Install from source

Compile mono from source.

Prerequisites

sudo apt-get -y install build-essential autoconf automake libtool zlib1g-dev pkg-config gettext

Download, compile and install

wget http://download.mono-project.com/sources/mono/mono-3.10.0.tar.bz2
tar xf  mono-3.10.0.tar.bz2
cd mono-3.10.0
./configure --prefix=/usr/local
make -j4
sudo make install

Clean up

cd .. && rm -rf mono-3.10.0

Install from GitHub

Prerequisites

sudo apt-get -y install build-essential autoconf automake libtool zlib1g-dev pkg-config gettext git

Download, compile and install

git clone http://github.com/mono/mono
cd mono
./autogen.sh --prefix=/usr/local
make get-monolite-latest
make -j4 EXTERNAL_MCS=${PWD}/mcs/class/lib/monolite/basic.exe
sudo make install

Configuration files need to be generated hence ./autogen.sh instead of ./configure. To compile mono you need mono. If you don't already have it, make get-monolite-latest downloads a lite version and EXTERNAL_MCS uses it.

Install from Docker

Install docker

curl -sSL https://get.docker.com/ubuntu/ | sudo sh

Download mono image

sudo docker pull mono:latest

Then run it

sudo docker run -it --rm mono:latest mono --version

Install from Continuous Integration packages

If you want the latest mono but don't want to compile it from source.

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://jenkins.mono-project.com/repo/debian sid main" | sudo tee /etc/apt/sources.list.d/mono-jenkins.list
sudo apt-get update
sudo apt-get install -y mono-snapshot-latest

The latest snapshot will be installed in /opt/mono-snapshot-XXXX.

Before running mono, set up environment variables like this

. mono-snapshot mono

You can see the list of installed snapshots

mono-snapshot

and switch to it like this

. mono-snapshot mono/20140807112602

Precompiled mono snapshot

If you want the latest mono, don't want to compile it from source and can't use apt-get or sudo.

ENVPATH=/home/mono/env

# save environment variables
cat > $ENVPATH <<'END'
export SNAPDATE=20141220092712
export MONO_HOME=/home/mono/mono-snapshot-$SNAPDATE
export MONO_PATH=$MONO_HOME/lib/mono/4.5
export MONO_CFG_DIR=$MONO_HOME/etc
export PATH=$MONO_HOME/bin:$PATH
export LD_LIBRARY_PATH=$MONO_HOME/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=$MONO_HOME/lib/pkgconfig:$PKG_CONFIG_PATH
END

# load environment
. $ENVPATH

# temp dir for extracting archives
TEMP=/tmp/mono-snapshot-${SNAPDATE}-temp

# start fresh
rm -rf $TEMP && mkdir -p $TEMP
rm -rf $MONO_HOME && mkdir -p $MONO_HOME

# download .debs and extract them into $TEMP dir
fw_get http://jenkins.mono-project.com/repo/debian/pool/main/m/mono-snapshot-${SNAPDATE}/mono-snapshot-${SNAPDATE}_${SNAPDATE}-1_amd64.deb
fw_get http://jenkins.mono-project.com/repo/debian/pool/main/m/mono-snapshot-${SNAPDATE}/mono-snapshot-${SNAPDATE}-assemblies_${SNAPDATE}-1_all.deb
dpkg-deb -x mono-*amd64.deb $TEMP
dpkg-deb -x mono-*assemblies*.deb $TEMP

# move /opt/mono-$SNAPDATE
mv $TEMP/opt/mono-*/* $MONO_HOME

# cleanup
rm mono-*.deb
rm -rf $TEMP

# replace /opt/mono-$SNAPDATE path
file $MONO_HOME/bin/* | grep "POSIX shell script" | awk -F: '{print $1}' | xargs sed -i "s|/opt/mono-$SNAPDATE|$MONO_HOME|g"
sed -i "s|/opt/mono-$SNAPDATE|$MONO_HOME|g" $MONO_HOME/lib/pkgconfig/*.pc $MONO_HOME/etc/mono/config

Mono will be installed in /home/mono/mono-snapshot-XXXX. You can load all necessary environment variables with . /home/mono/env.

Setup NuGet

NuGet is a package manager. It downloads packages from a central repository via SSL. For this reason it is necessary to import trusted root sertificates.

For all users:

sudo mozroots --import --sync --machine
echo -e "y\n\y\ny\n" | sudo certmgr -ssl -m https://nuget.org

For current user only:

mozroots --import --sync
echo -e "y\n\y\ny\n" | certmgr -ssl https://nuget.org

Check

$ mono --version
Mono JIT compiler version 3.10.0 (tarball Mon Oct 20 11:45:51 EEST 2014)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen