F# on (Ubuntu) Linux with Mono and Monodevelop

This week, I’m attending the Java Posse Roundup to learn about the interesting things happening on the JVM, meet smart people, and hopefully write some Scala and Clojure code. One of the more surprising emails that I got after registering for the conference came from Dick Wall who asked if I could take an afternoon during the conference to hack some F# with him. Dick prefers to run Ubuntu, and I have wanted to revisit F# on Ubuntu ever since I played around with it a few months back, so I set about installing F# and getting it to run with Monodevelop in Ubuntu.

Below is the process that I used to get everything working on my machine. I don’t claim that this is the best way to do things or that it will even work for anyone else. However, I didn’t find much up to date documentation on the web about running F# on Ubuntu, so hopefully this useful to others. I’ll do my best to keep this up to date, so feel free to post comments on your experiences.

Background

Unlike most installs on Ubuntu, mono is tricky. For various reasons, the mono packages in the Ubuntu repositories are significantly out of date, so you will have to build from source to get even semi-recent updates. I decided that I did not want to overwrite the mono installation that ships with Ubuntu, so these instructions will set you up with a parallel mono installation in /opt/mono.

Getting Started

Before you get started, you’ll need to make sure a few prerequisites are installed. You probably already have most of these if you’re a dev.

sudo apt-get install git build-essential autoconf libtool automake

Next, create (or make sure you have permission to access) /opt/src and /opt/mono since that’s where you’ll be putting all of the fresh mono bits.

cd ~
mkdir src 
sudo mv ./src /opt 
mkdir mono 
sudo mv ./mono /opt

Installing mono

It’s easy to install a parallel mono environment once you know what you’re doing. First, you’ll need a couple of dependencies.

sudo apt-get install bison gettext

Next, download the mono source. I chose to install mono 2.10 (which was just released at the time of this writing), but you can install whatever version you’d like by modifying the git commands below.

cd /opt/src 
git clone git://github.com/mono/mono mono 
cd mono 
git branch mono-2-10 remotes/origin/mono-2-10 
git checkout mono-2-10

Now build and install mono. Note: don’t forget the –prefix option since that’s how you avoid overwriting the default mono installation.

./autogen.sh --prefix=/opt/mono 
make 
make install

Setup a Parallel mono Environment

Now that your parallel instance of mono is installed in /opt/mono, you need a way to tell your bash environment to use it instead of Ubuntu’s default mono when you’re developing. You can do that with a short bash script as described on the parallel mono page.

You can create the script anywhere. I put mine in my home folder

vim ~/mono-dev-env

Add the following lines to your script to configure the parallel mono environment.

#!/bin/bash 
MONO_PREFIX=/opt/mono 
GNOME_PREFIX=/usr 
export DYLD_LIBRARY_FALLBACK_PATH=$MONO_PREFIX/lib:$DYLD_LIBRARY_FALLBACK_PATH 
export LD_LIBRARY_PATH=$MONO_PREFIX/lib:$LD_LIBRARY_PATH 
export C_INCLUDE_PATH=$MONO_PREFIX/include:$GNOME_PREFIX/include 
export ACLOCAL_PATH=$MONO_PREFIX/share/aclocal 
export PKG_CONFIG_PATH=$MONO_PREFIX/lib/pkgconfig:$GNOME_PREFIX/lib/pkgconfig 
export PATH=$MONO_PREFIX/bin:$PATH

Now tell bash to use your new environment.

source ~/mono-dev-env

You can test that everything is working by running mono -V. Note that if you close your terminal window at any point during the rest of the install, you will have to source the mono-dev-env script again.

$ mono -V 

Mono JIT compiler version 2.10 (mono-2-10/1630b8e Thu Feb 10 18:40:28 EST 2011) 
Copyright (C) 2002-2011 Novell, Inc and Contributors. www.mono-project.com 
    TLS:           __thread 
    SIGSEGV:       altstack 
    Notifications: epoll 
    Architecture:  x86 
    Disabled:      none 
    Misc:          softdebug 
    LLVM:          supported, not enabled. 
    GC:            Included Boehm (with typed GC and Parallel Mark)

Install F#

There are a couple of ways to get F# running under mono, but I chose to also build F# from source. A mono-friendly version of the F# source lives on github. Since you will use F# Interactive, you’ll also want to grab libgdiplus, which F# Interactive requires to run properly.

sudo apt-get install libgdiplus

With that out of the way, download, build, and install F# from github. Again, don’t forget the –prefix option. Now is a good time to grab a drink since F# can take a while to build.

cd /opt/src 
git clone git://github.com/fsharp/fsharp 
cd fsharp 
autoreconf 
./configure --prefix=/opt/mono 
make 
make install

When you’re done, you can run the following to make sure everything went well.

fsc 
Microsoft (R) F# 2.0 Compiler build (private) 
Copyright (c) 2002-2010 Microsoft Corporation. All Rights Reserved.

error FS0207: No inputs specified

Note that you can also run F# interactive at this point, too.

fsi

Microsoft (R) F# 2.0 Interactive build (private) 
Copyright (c) 2002-2010 Microsoft Corporation. All Rights Reserved.

For help type #help;;

> exit 0;;

Right now you already have a full blown F# development environment at your fingertips, so you could stop at this point. I prefer to have monodvelop since I find that having mouse-over type information is very helpful when writing F#.

Install monodevelop’s Dependencies

Before you can install monodevelop, you’ll need to grab a few of dependencies, but those dependencies have a few dependencies of their own. Fortunately, you can get all of those from the Ubuntu repositories.

sudo apt-get install libgtk2.0-dev libgconf2-dev libglade2-dev libgnomecanvas2-dev libgnomeui-dev

Now you’re ready to install gtk-sharp, the first monodevelop dependency. Check out and build the most recent release of gtk-sharp (which at the time of this writing is 2-12).

cd /opt/src 
git clone git://github.com/mono/gtk-sharp gtk-sharp 
cd gtk-sharp 
git branch gtk-sharp-2-12-branch remotes/origin/gtk-sharp-2-12-branch 
git checkout gtk-sharp-2-12-branch 
./bootstrap-2.12 --prefix=/opt/mono 
make 
make install

Next up is mono-addins.

cd /opt/src 
git clone git://github.com/mono/mono-addins.git mono-addins 
cd mono-addins 
./autogen.sh --prefix=/opt/mono 
make 
make install

Finally, you’ll also need gnome-sharp.

cd /opt/src 
git clone git://github.com/mono/gnome-sharp
cd gnome-sharp
./bootstrap-2.24 --prefix=/opt/mono 
make 
make install

Install monodevelop

With the dependencies out of the way, you’re clear to install monodevelop. I  got version 2.4 of monodevelop since the F# plugin does not work with the latest builds of monodevelop at the time of writing.

cd /opt/src 
git clone git://github.com/mono/monodevelop 
cd monodevelop 
git branch 2.4 remotes/origin/2.4 
git checkout 2.4 
./configure --prefix=/opt/mono --profile=core 
make 
make install

Install fsharpbindings

The fsharpbindings project is a plugin that makes adds support for F# to monodevelop. I had trouble getting the latest source working with a parallel mono 2.10 environment on Ubuntu, but I was able to fix the problems with my own branch of the plugin. I’ve put in a pull request, but for the time being, pull from my fork. I’ll update this post once the main fsharpbindings project works with Ubuntu and mono 2.10.

cd /opt/src
git clone git://github.com/ChrisMarinos/fsharpbinding.git 
cd fsharpbinding/ 
./configure.sh 
make 
make install

One Last Bit of Setup

You’re almost there. One last bit of setup is required since the current version of fsharpbindings uses different names for the F# compiler and F# Interactive executables. Create symlinks to get the bindings to work.

cd /opt/mono/bin 
ln -s ./fsi ./fsharpi 
ln -s ./fsc ./fsharpc

Try it Out!

If everything went according to plan (yeah, right), you should have a full blown F# IDE. Test it out!

Note: When testing the install, I received several weird errors the first time I created a F# project in monodevelop. Monodevelop segfaulted once and also complained about not being able to find “System.Array”. I’m not sure why these errors occur, but simply restarting monodevelop fixed them for me. I’ll update if and when I figure out more.

cd ~ 
monodevelop

You should be able to try out F# by running code in the F# interactive window similar to the one in Visual Studio.

You can also create a console application.

Summary

I hope you found the above install process useful, but feel free to leave comments or otherwise contact me if you find problems. F# on mono has come a long way since I last played around with it, and I’m looking forward to watching (and helping) things progress more in the future.

Special thanks to Jay Wren for helping me put this together!

This entry was posted in F#, mono. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

17 Comments

  1. Joel
    Posted February 22, 2011 at 11:02 pm | Permalink

    For various reasons, the mono packages in the Ubuntu repositories are significantly out of date

    What reasons, and why haven’t these reasons been killed with fire yet?

  2. Chris Marinos
    Posted February 23, 2011 at 12:32 am | Permalink

    @Joel-

    My (possibly misinformed) understanding is that there are a couple of objective reasons:

    -Mono changes frequently enough that they are worried about breaking some of the apps that ship with Ubuntu that rely on mono
    -Mono is tricky to package for Debian/Ubuntu

    Probably more important is the subjective reason; I hear the Debian folks aren’t big fans of mono due to the Microsoft connection. I think it’s silly, but that’s my understanding of it. However, I’m not an expert on the politics of the open source world, so don’t take my word as law.

    -Chris

  3. Arved Sandstrom
    Posted February 23, 2011 at 1:27 am | Permalink

    Very nice build process description. I’m working with a F# console app right now on Ubuntu 10.10 after finishing this process. Just enough detail to get things properly done.

    The F# is gravy; I was happy to run across such a nice description of building a recent mono, seeing as how with the packages I was stuck with 2.6.7. For the past while I’ve been doing mono C# development on Mac OS X 10.6, where the available version is currently 2.8.2, hence also providing me with C# 4.0. But this is even better. The F# Interactive window is also working nicely. Many thanks.

  4. Chris Marinos
    Posted February 23, 2011 at 1:30 am | Permalink

    @Arved-

    I’m glad that I could help out! As I said in the post, much of the thanks should go to Jay Wren who helped me figure out a lot of the mono build process in particular.

  5. Geoff
    Posted February 23, 2011 at 3:48 am | Permalink

    Chris,

    Wow! Thanks!

    I built a computer and installed Ubuntu. My only experience with *nix was Xenix on a Tandy in the late 70′s and a brief encounter with Slackware a few years ago.

    So, raw Ubuntu installation and someone with no Linux experience just followed your instructions to a tee and was successful!

    F# installed just fine, same for MonoDevelop.

    I have no idea what most of the commands were, so this is amazing. You da man!

    — Geoff

  6. Chris Marinos
    Posted February 23, 2011 at 7:58 am | Permalink

    @Geoff-

    Thanks. Glad I could help!

    -Chris

  7. Jason McCampbell
    Posted March 15, 2011 at 1:23 am | Permalink

    Chris, thanks very much for fixing/posting your changes to the F# MonoDevelop plug-in for Mono 2.10. I was just debating going back a rev or debugging the issue myself but was hoping someone had already solve it. Thanks!

    Regards,
    Jason

  8. Chris Marinos
    Posted March 15, 2011 at 4:53 pm | Permalink

    @Jason-

    Glad I could be of service!

    -Chris

  9. Posted March 19, 2011 at 10:24 am | Permalink

    Somewhat dissappointing that so many steps are required – truly this is the UNIX Way :) Anyways, followed this guide and got everything set up – thanks for that!

  10. Chris Marinos
    Posted March 19, 2011 at 3:57 pm | Permalink

    @Dmitri-

    Glad it worked for you. If the Ubuntu repositories were more up to date the install could be shrunk down to one or two steps, but at least building from source is a good learning exercise! :-)

    -Chris

  11. Posted June 10, 2011 at 11:58 am | Permalink

    I’m afraid I couldn’t get all the way there — making f# failed with the following

    make -C src/fsharp all
    make[1]: Entering directory `/opt/src/fsharp/src/fsharp'
    make -C FSharp.Build-proto all
    make[2]: Entering directory `/opt/src/fsharp/src/fsharp/FSharp.Build-proto'
    MONO_PATH=/opt/src/fsharp/lib/bootstrap/4.0/ mono --debug /opt/src/fsharp/lib/bootstrap/4.0/fsc.exe -o:.libs/4.0/FSharp.Build-proto.dll -r:/opt/src/fsharp/lib/bootstrap/4.0/FSharp.Core.dll -r:/usr/lib/mono/4.0/Microsoft.Build.Engine.dll -r:/usr/lib/mono/4.0/Microsoft.Build.Framework.dll -r:/usr/lib/mono/3.5/Microsoft.Build.Tasks.v3.5.dll -r:/usr/lib/mono/3.5/Microsoft.Build.Utilities.v3.5.dll -r:/usr/lib/mono/4.0/mscorlib.dll -r:/usr/lib/mono/4.0/System.Core.dll -r:/usr/lib/mono/4.0/System.dll -r:/usr/lib/mono/4.0/System.Numerics.dll --define:BUILDING_WITH_LKG --define:NO_STRONG_NAMES --define:TRACE --define:FX_ATLEAST_35 --define:MONO --define:CODE_ANALYSIS --define:DEBUG --define:FX_ATLEAST_40 --doc:.libs/4.0/FSharp.Build-proto.xml --version:4.0.0.0 -g --mlcompatibility --noframework --fullpaths --times --nowarn:9 --target:library --resource:.libs/FSBuild.resources .libs//FSBuild.fs /opt/src/fsharp/src/fsharp/FSharp.Build-proto/../../utils/CompilerLocationUtils.fs /opt/src/fsharp/src/fsharp/FSharp.Build-proto/../FSharp.Build/CreateFSharpManifestResourceName.fsi /opt/src/fsharp/src/fsharp/FSharp.Build-proto/../FSharp.Build/CreateFSharpManifestResourceName.fs /opt/src/fsharp/src/fsharp/FSharp.Build-proto/../FSharp.Build/Fsc.fsi /opt/src/fsharp/src/fsharp/FSharp.Build-proto/../FSharp.Build/Fsc.fs
    WARNING: The runtime version supported by this application is unavailable.
    Using default runtime: v1.1.4322

    ** (/opt/src/fsharp/lib/bootstrap/4.0/fsc.exe:7316): WARNING **: The class System.IEquatable`1 could not be loaded, used in mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

    ** (/opt/src/fsharp/lib/bootstrap/4.0/fsc.exe:7316): WARNING **: Missing method get_Parameter in assembly /opt/src/fsharp/lib/bootstrap/4.0/fsc.exe, type BuildPhase

    Unhandled Exception: System.TypeLoadException: Could not load type 'System.IEquatable`1' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
    make[2]: *** [.libs//4.0/FSharp.Build-proto.dll] Error 1
    make[2]: Leaving directory `/opt/src/fsharp/src/fsharp/FSharp.Build-proto'
    make[1]: *** [all] Error 2
    make[1]: Leaving directory `/opt/src/fsharp/src/fsharp'
    make: *** [all] Error 2

    You don’t have any idea what the problem might be or how I might get around it?

  12. Posted June 10, 2011 at 12:04 pm | Permalink

    Ah, I solved my own problem, which was caused by sudo-ing everything.

  13. Chris Marinos
    Posted June 10, 2011 at 12:05 pm | Permalink

    @Chris-

    Hmm, I’m not positive, but it looks like something is wrong with your mono runtime. Did you make sure to source your parallel mono environment? Make sure that the output of mono -V looks like what I described in the post. If that looks the same and you followed all the steps that I outlined for building mono from source, I’m not sure.

    -Chris

  14. Vince
    Posted June 23, 2011 at 2:24 pm | Permalink

    Hi, Chris. I followed the steps on 11.04, and I believe everything installed correctly. However, when I launch monodevelop, I get this:

    FATAL ERROR [2011-06-23 09:23:08Z]: MonoDevelop failed to start. Some of the assemblies required to run MonoDevelop (for example gtk-sharp, gnome-sharp or gtkhtml-sharp) may not be properly installed in the GAC.
    System.MissingMethodException: Method not found: ‘System.Type.op_Equality’.
    at GLib.Object.GetObject (IntPtr o, Boolean owned_ref) [0x00000] in :0
    at GLib.Object.GetObject (IntPtr o) [0x00000] in :0
    at Gtk.Settings.get_Default () [0x00000] in :0
    at MonoDevelop.Ide.IdeStartup.Run (System.String[] args) [0x00000] in :0
    at MonoDevelop.Startup.MonoDevelopMain.Main (System.String[] args) [0x00000] in :0

    Any ideas?

    Thanks,
    Vince

  15. Chris Marinos
    Posted June 23, 2011 at 2:33 pm | Permalink

    @Vince-

    I haven’t tried on 11.04, but based on the error, it sounds like you’re missing gtk-sharp, gnome sharp, or gtkhtml-sharp. Either you aren’t running from the parallel mono environment and need to run “source ~/mono-dev-env” or one of the dependencies failed to install correctly. Also, I’m not sure if gtkhtml-sharp is a new dependency, or if it was installed as part of the other steps. Are you sure that you’re trying to install Mono 2.10 and Mono Develop 2.4?

    -Chris

  16. Dustin Rodriguez
    Posted May 18, 2013 at 12:15 am | Permalink

    Hey, thanks heaps for these instructions. I am nearly there! I got all the way to actually installing monodevelop but ran into a problem when executing the branch command. The git clone command worked successfully, I changed into the monodevelop directory, then executed ‘git branch 2.4 remotes/origin/2.4′ and received the following error message:
    fatal: Not a valid object name: ‘remotes/origin/2.4′.

    I notice on the monodevelop site that they now have a 3.0 version. Perhaps 2.4 has been moved to somewhere else in the repository? I am a complete beginner when it comes to git and don’t know how to list what is actually available in remotes/origin to see if there is maybe a monodevelop-2.4 or something like that. I realize these instructions are kinda old now, but they still work for the newest non-beta version of mono itself, and it was the first search result on DuckDuckGo for ‘mono f#’ so if it’s not too much trouble could you update them?

    Thanks in advance!

  17. Chris Marinos
    Posted May 24, 2013 at 5:02 am | Permalink

    @Dustin-

    Yeah, the instructions are definitely a bit outdated. I believe F# comes out of the box in mono/monodevelop these days, and I’d recommend checking out http://fsharp.org/ for more info on how to get everything running with the latest bits.

    As far as your question about the branch, going out to github, it looks like 2.4 is still in the repository, but it’s a tag now, not a branch. You should be able to do a “git checkout monodevelop-2.4 to get to that version of the code.

    Sorry for the long turnaround on my response. Please feel free to send another reply or send me an email at [chris] @ [this web site]

2 Trackbacks

  1. By F# Discoveries This Week 02/25/2011 « F# Central on February 25, 2011 at 8:26 pm

    [...] hints that may reduce some Googling as you go down the path of creating your first package.” Chris Marinos’s F# on (Ubuntu) Linux with Mono and Monodevelop “Below is the process that I used to get everything working on my machine. I don’t claim that [...]

  2. [...] stay accessible to the root command when installing. These steps are based on Chris’s article found here. git clone git://github.com/fsharp/fsharp cd fsharp autoreconf ./configure –prefix=/opt/mono-2.10 [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>