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!