Thursday, September 5, 2013

How I set up MonoDevelop on Linux

Mono and Linux is a complex story - currently the fact is that no mainstream Linux distribution gives you the most recent .NET development tools (yes I know about arch - I can recommend using arch or manjaro if you want 'the easy way'). Most of us Linux users can be happy if your Linux distribution has a mono run time from this decade.

MonoDevelop runs on Linux quite well (in case you use a light theme - see MonoDevelop 4.0 and dark themes). Many developers from Xamarin are Linux users and run MonoDevelop on Linux every day (but without a dark theme :)).

It is possible to get a very good looking monodevelop environment on Linux as well. I'll try to explain how I do it and show a screenshot as 'proof of concept' :)

Parallel Mono Environment

To get the latest mono you'll need to build a parallel mono environment. This is far easier than it sounds and wont affect the mono your distribution has. (But you need to install a mono in your distribution for building a mono from the repositories)

First you need a script for 'switching' to the parallel environment.  I use this script for doing it:

#!/bin/bash
MONO_PREFIX=/opt/mono
export DYLD_LIBRARY_PATH=$MONO_PREFIX/lib:$DYLD_LIBRARY_PATH
export LD_LIBRARY_PATH=$MONO_PREFIX/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=$MONO_PREFIX/include
export ACLOCAL_PATH=$MONO_PREFIX/share/aclocal
export PKG_CONFIG_PATH=$MONO_PREFIX/lib/pkgconfig
export MONO_TLS_PROVIDER=legacy

PATH=$MONO_PREFIX/bin:$PATH

The best way is to build mono, gtk# (gtk-sharp-2-12-branch) and gnome-sharp from the sources found on github(I hope you're familiar with git):

https://github.com/mono/mono
https://github.com/mono/gtk-sharp
https://github.com/mono/gnome-sharp

For building mono & gtk-sharp your distribution needs some prerequisites - either you follow what the configure/bootstrap scripts tell you or try something like sudo apt-get build-dep monodevelop (Note: On current ubuntu/monodevelop you'll need more packages like libtool but the build scripts will tell you what's needed).
You need to run the configure/bootstrap scripts with the option --prefix=/opt/mono - and then it installs 'as usual' with make/make install.

Building MonoDevelop

Get monodevelop from https://github.com/mono/monodevelop then switch to your parallel mono environment and type inside the monodevelop directory: ./configure ; make

And just run it with "make run" - that's all.

Some tips: Adjust the fonts (I use Source Code Pro for the text editor and Source Sans Pro almost everywhere else).

Get the Xamarin gtk theme from https://github.com/mono/xamarin-gtk-theme (you may need to set the prefix here to --prefix=/usr) and enable it in Environment->Language.

The end result should like this:


Ok I agree that there is a drawing error in the tab bar - but that's due a graphic device driver bug (it should render a horizontal linear gradient - chrome tabs suffer from the same bug on my machine).

Conclusion

It's hard to get a .NET environment running on Linux these days - but it's doable :). Btw. we could need help improving the monodevelop Linux client - esp. dark theme support is lacking a bit :)


For the Lazy

Lately I've been reinstalling Ubuntu 17.10 and I did following (may be helpful):

sudo apt-get install autoconf libtool-bin libglade2-dev libgnomeui-dev cmake libssh-dev libssh2-1* nuget mono-devel git intltool curl

git clone https://github.com/mono/mono
cd mono
./autogen.sh --prefix=/opt/mono
make get-monolite-latest
make; sudo make install; cd ..

git clone --branch gtk-sharp-2-12-branch https://github.com/mono/gtk-sharp.git
cd gtk-sharp
./bootstrap-2.12 --prefix=/opt/mono
make; sudo make install; cd ..

git clone https://github.com/mono/gnome-sharp.git
cd gnome-sharp
# needed to edit Settings.cs atom ./sample/gconf/Settings.cs
./bootstrap-2.24 --prefix=/opt/mono
make; sudo make install; cd ..


git clone https://github.com/mono/xamarin-gtk-theme.git
cd xamarin-gtk-theme
 ./autogen.sh --prefix=/usr
make; sudo make install; cd ..

# Building monodevelop (git clone may be different for you)
git clone git@github.com:mono/monodevelop.git 
cd monodevelop
./configure
make
make run 

# INSTALL MSBUILD
# This is broken:
git clone https://github.com/mono/msbuild
cd msbuild
git checkout -b xplat-master origin/xplat-master
./cibuild.sh --scope Compile --target Mono --host Mono

# Alternative - get an os x box grab msbuild from there and install and install it # in opt/mono/lib/mono/msbuild/15.0/bin/MSBuild.dll

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/mono-official.list

sudo apt-get update
sudo apt-get install msbuild
sudo cp -R /usr/lib/mono/msbuild/15.0 /opt/mono/lib/mono/msbuild
sudo cp /usr/bin/msbuild /opt/mono/bin

 
sudo mozroots --import --machine --sync
sudo certmgr -ssl -m https://go.microsoft.com
sudo certmgr -ssl -m https://nugetgallery.blob.core.windows.net
sudo certmgr -ssl -m https://nuget.org

git clone https://github.com/fsharp/fsharp
cd fsharp
./autogen.sh --prefix=/opt/mono
make; sudo make install; cd ..

# install PCL
# go to windows C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable
# the portable libraries should end up in /opt/mono/lib/mono/xbuild-frameworks/.NETPortable
# for me it looks like:
# /opt/mono/lib/mono/xbuild-frameworks/.NETPortable$ ls
# v4.0  v4.5  v4.6

# Building monodevelop (git clone may be different for you)
git clone git@github.com:mono/monodevelop.git
cd monodevelop
./configure
make
make run