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

32 comments:

  1. Although Mono and OpenSUSE also be a more yet complex story, I recommend this flavor for Mono dev. Just grab Mono 3.2.1 and Monodevelop 4.0.12 from http://download.opensuse.org/repositories/Mono:/Factory/openSUSE_12.3/ and happy codding.

    ReplyDelete
  2. The last time I remember building MD4 (which was a few months ago now) then it wasn't that difficult, but I am using openSUSE with an additional Mono repo (IIRC).

    As for the theme - I lasted about five minutes with that hideously eye-burning Mac-cloning brightness and tried to fix the worst of it myself so that it at least worked with my theme. It is up on GitHub if anyone wants it (https://github.com/IBBoard/monodevelop/commit/1c66ef096ef7ec09e3a1f6fedd2d019ebd6933ee) but I didn't bother with a pull request because Xamarin likes being Mac-esque too much to be a good desktop citizen and use the theme properly :\

    TBH, I've almost given up on doing .NET in Linux. When Xamarin was formed then it all looked good and rosey, but there's just not the interest. Yeah, MonoDevelop still works, but we're treated as third-class citizens.

    ReplyDelete
    Replies
    1. Not everyone has openSUSE - there are really many distributions. And I doubt that I would switch my distribution of choice just because XXX is running a tiny bit easier :).

      Currently I develop MonoDevelop using Linux. It's true that we're Mac centric these days - but Canonical tries to push the Linux desktop to the Mac look&feel as well.

      We like the Mac l&f - but not everyone does - we know that.

      If there is enough interrest in the linux community maybe someone makes a better monodevelop shell - it's possible to do - the shell is abstracted out of the rest :)

      Delete
  3. "It's hard to get a .NET environment running on Linux these days - but it's doable"

    I think it would be fairer - and more honest - if Xamarin would just tell everybody that they don't care anymore about Linux and that they are now making their money almost exclusively with selling developer tools for OS X that allow you to write iOS apps in C#.

    The times when Miguel de Icaza wanted Linux and Mono on Linux to be first class citizens are long gone. I can't say that I blame him or his team; we all need to put food on our tables somehow. I just think it would be honest for Xamarin to clearly say it as it is: "Mono for Linux is not even an afterthought anymore, it's dead and we just wish to forget the whole thing."


    ReplyDelete
    Replies
    1. If we wouldn't care about Linux we wouldn't ensure that MonoDevelop keeps running.

      Thesis: We don't care about Linux.
      Proof of the opposite: Look at the monodovelop git log and search for Linux/linux and you'll find many linux specific patches (old&new).
      q.e.d.

      But it's true that we make money with OS X - but it's possible that a .NET community can form on Linux - it's all there. That this doesn't happen is not the fault of Xamarin.

      I can promise that we won't let Linux our Linux platform support fail because too many of us are using it for their work - it's that easy.
      Only because we don't sell our products on Linux doesn't mean we don't care.

      Delete
    2. Fingers crossed, personally I find it works very well on linux (esp under pmono - _plug_), I use it daily as my main editor/debugger.

      Keep em coming!

      Delete
  4. I'm trying to build MD4 on CentOS6.4, and I can't use git: port 9418 is closed to me. Is there a way to build it that doesn't depend on git? Thanks!

    ReplyDelete
    Replies
    1. Github allows to download the repository as .zip - or you can choose using the git https protocol.

      Delete
    2. Hi Mike,
      Thanks - but I don't have any trouble downloading the tar from github, I have trouble building it. There's a PreBuild section in some of the .csproj files that calls git, and some of the makefiles call git update also. I haven't discovered a way to get around that without editing the individual files.
      In addition, the tar doesn't have some of the projects in it that the solution is trying to build. This is the 4.0.12 release, which is supposed to be stable!
      I'm trying to put together a set of tars and instructions for a team of developers, and I had hoped to be able to point them to a download in cause they wanted to install a newer release.
      Rob

      Delete
    3. I forgot about the git submodules - right without git it's problematic :(

      Delete
  5. I'm trying to build MD4 on Ubuntu 13.10beta and am having a horrible time of it:

    I'm installing in a parallel environment so I can keep my 3.x working while if figure out what's wrong with v4.

    I've compiled mono and the other pre-reqs from git and installed them into my /opt/mono prefix. However, I get the following + many more errors when I finally get to building MD4:

    ```
    Building ./Main.sln
    xbuild /verbosity:quiet /nologo /property:CodePage=65001 ./Main.sln /property:Configuration=Debug
    : warning CS1701: Assuming assembly reference `glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f' matches assembly `glib-sharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f'. You may need to supply runtime policy
    ClassDescriptor.cs(186,23): error CS0012: The type `GLib.IIcon' is defined in an assembly that is not referenced. Consider adding a reference to assembly `gio-sharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f'
    DND.cs(404,15): error CS0234: The type or namespace name `SideType' does not exist in the namespace `Gtk'. Are you missing an assembly reference?
    ```

    It looks like it's having problems with GTK#, but I've tried installing both the 2.12 and master branch with no luck.

    ReplyDelete
    Replies
    1. My ./configure output looks like: http://pastebin.com/DV0aPLUc

      Delete
  6. Full make output: http://pastebin.com/uP7Q0wwg

    I've done a lot of web searches over the past couple of days, but while I've only found people pasting the same error output; I haven't found a solution. Help me Obi Wan, you're my only hope. :)

    I've completely deleted my gits, /opt/mono, re-cloned and rebuilt everything - and still come to this same impass.

    Any ideas?

    ReplyDelete
  7. Have you compiled gtk# from source ?
    1) Ensure that you're in the 'gtk-sharp-2-12-branch' of gtk# (master doesn't work)
    2) Run './bootstrap-2.12 --prefix=/opt/mono'
    3) The output says at the end which optional assemblies get to be build. If all say 'yes' then it's ok. If not you need to install the dev package from apt-get (gtk-dev etc.)

    Are you in the 'mono environment' all the time ? (The script above - you should run it with 'source ~/mono-dev-env' or something similiar.

    ReplyDelete
    Replies
    1. Thanks for taking the time to reply and help, Mike!

      1) Yes. I've tried using that specific branch.
      2) Yes. I've specified the prefix on all of my bootstrap, autogen, and/or configure commands for each component.
      3) Everything looked good as I recall (will recheck, see below).

      I have been using the script from the parallel installation instructions I found on the mono site. I see that it differs from yours in one regard: It sets DYLD_FALLBACK_LIBRARY_PATH, where yours sets DYLD_LIBRARY_PATH.

      I'm going to build things from scratch again using your version, and will report back here ASAP. Thanks again for your assistance!

      Delete
    2. I got it running! I'm not sure what the difference was this time (either the env. var above, or just something that was hanging on through all my 'make clean's).

      I redownloaded and rebuilt everything from scratch. I've recorded my specific process here: http://pastebin.com/raw.php?i=Rtzv4AJL

      A couple of observations that you might want to incorporate above:

      a) Your environment script references /opt/gnome. Is there supposed to be anything in there? the only build prefix you reference is /opt/mono.

      b) Your environment script tries to start Monodevelop in /opt/monodevelop... but again, your instructions only mentioned the /opt/mono prefix. I just changed the script to use /opt/mono... but maybe you've been building Monodevelop for the /opt/monodevelop prefix instead?

      And one final question:

      I'm trying to manually add the Monogame-SDL2 (https://github.com/flibitijibibo/MonoGame.git) add-in. From what I can see with the other add-ins, it looks like I should just put the files in a subdirectory of ~/.local/share/MonoDevelop-4.0/LocalInstall/Addins. However, I'm not seeing it as a new project option when I'm doing that.

      Which files exactly do you need to copy into that folder? I was trying everything in the release build of the project template directory, but that doesn't seem to work.

      Thanks again for letting me bounce my problems off you here.

      Delete
    3. Nice to hear :)

      a) I must admit that I didn't read the environment script - ever :)
      b) See a) I always start with 'make run' :)

      final: have you tried using the addin manager ?

      Delete
    4. >have you tried using the addin manager

      Yes. Here are my observations from that:

      a) MonoGame doesn't appear in the gallery, so you have to download "MonoGame 3,0.1 for Xamarin Studio" at https://monogame.codeplex.com/releases/view/102870... which is not very intuitive for Linux users since there's no Xamarin Studio for Linux.

      b) Anything built with it will then fail due to missing DLLs, until you go download the libgdiplus source and compile that into /opt/mono.

      c) The output projects then have the year-old showstopping bug (https://github.com/mono/MonoGame/issues/628) of having a version of OpenTK that fails to set the window size correctly. Game windows stick to 640x480, no matter what you specify for backbuffer width/height.

      That's why I'm trying to use the Monogame-sdl version instead - it's the only version I've seen that actually works. But, compiling the project within ProjectTemplates and moving the Release directory into AddIns (and renaming it to MonoDevelop.Monogame) doesn't appear to work. It doesn't appear in my list at all when I do that.

      Delete
    5. This comment has been removed by the author.

      Delete
    6. Thanks to your instructions and 3vi1's dump at http://pastebin.com/raw.php?i=Rtzv4AJL , I was finally able to install monodevelop from sources. I followed the script from a clean Ubuntu 13.10 installation.
      After step D I needed to do
      sudo apt-get install libglade2-dev libgnomecanvas2-dev libgnome2-dev libgnomeui-dev
      .. and of course install mono-complete prior to step A.

      Thanks to both of you!

      Delete
  8. Hey Mike: I've worked around my Monogame-SDL2 issues by copying in my DLLs over those installed by the .mpack.

    But I have found one last (?) issue with my parallel environment: It seems impossible to actually build mono-tools from source.

    The current mono-tools git doesn't seem to build when used with a Mono3 environment (even after I built/installing gnome-sharp and everything else I suspected it might use).

    The 2.10 zip snapshot also fails to build. It says `gsharp/Makefile.in' is missing during the autogen!

    The 2.11 zip is missing almost all the files (it's only 84KB!), and has apparently been broken forever from what I see other people have posted.

    Have you been able to actually build mono-tools from the git? I'm trying to build it, because I notice that the 2.10 from the ubuntu packages likes to throw sigsegv's when you click the close window button (on KDE) instead of selecting File|Exit.

    ReplyDelete
    Replies
    1. I never needed mono-tools - you may ask in #mono on irc.gnome.org - there are the mono devs :)

      Delete
    2. I filed a bug in the bugzilla last night, but maybe I will go ping the devs too. Thanks for the suggestion!

      Delete
  9. Hi,
    I've now been working 2 days straight to get monodevelop working in a parallel environment on lubuntu 13.10. I think I've tried all the tips above. Cleaned and cloned multiple times. Any chance you could share that pastebin again 3vi1?

    Quote 3vi1:
    "I redownloaded and rebuilt everything from scratch. I've recorded my specific process here: http://pastebin.com/raw.php?i=Rtzv4AJL"

    ReplyDelete
  10. When I run ./configure in the monodevelop directory I get this output:
    http://pastebin.com/zcxsXpih
    As you can see from the output it uses mono and gmcs from /usr/bin and not /opt/mono-3
    I have run the switch environment script with "source ~/mono3-env.sh". And I have checked that /opt/mono-3/ was set on the different paths.

    ReplyDelete
  11. I finally got Monodevelop 4.1.13 working !!
    My main problem was that I ran the environment script as the normal user, but I ran the configure; make; make install as root user. So the root user did not have the correct envirnoment variables set.

    ReplyDelete
  12. I'm having this problem after make:

    ./JavaLanguageBinding.cs(31,28): error CS0234: The type or namespace name `Dom' does not exist in the namespace `MonoDevelop.Projects'. Are you missing an assembly reference?
    ./JavaLanguageBinding.cs(32,28): error CS0234: The type or namespace name `Dom' does not exist in the namespace `MonoDevelop.Projects'. Are you missing an assembly reference?
    ./JavaLanguageBinding.cs(34,28): error CS0234: The type or namespace name `CodeGeneration' does not exist in the namespace `MonoDevelop.Projects'. Are you missing an assembly reference?
    ./JavaLanguageBinding.cs(109,10): error CS0246: The type or namespace name `IParser' could not be found. Are you missing an assembly reference?
    ./JavaLanguageBinding.cs(113,10): error CS0246: The type or namespace name `IRefactorer' could not be found. Are you missing an assembly reference?

    I believe is a problem with Java Binding. Any help?

    ReplyDelete
  13. I would love to develop .net/f# under linux (opensuse) - but right now monodevelop works but will hang/extremly slow down my system (KDE).

    Unusable sorry

    ReplyDelete
    Replies
    1. When it hangs try to kill -QUIT and give me the thread state output. Maybe it's something I can fix.

      Atm I work on Ubuntu 14.04 and it runs smooth for me.

      Delete
  14. This comment has been removed by the author.

    ReplyDelete
  15. There is link that i found it gives simple and easy step by step tutorial for installation of monodevelop on linux it works and easy to implement in 10 minutes
    http://geeksprogrammings.blogspot.com/2014/07/install-monodevelop-on-linux.html

    ReplyDelete