-Kipling
This page describes how to install C# and Mono on the Raspberry Pi 2. This page is one part of a series of web pages which describe how to install C# and Mono on the Raspberry Pi and also how to setup a useful remote compilation and debugging toolchain for it.
Note: Before you continue with any of the steps on this page be aware you need to install Mono on the armhf version of the Linux operating system. Mono will not install on an armel distribution. Fortunately recent versions of the Raspbian operating system are all armhf so this is not generally a problem. However if you are using other distributions and run into installation issues you may wish to confirm which type you are using. The hardware and software setup for the Raspberry Pi is pretty standard and is as described on the Hardware and Software Setup page of this project.
Assuming you have networking configured and also have full Internet access on your Raspberry Pi, you can install Mono by issuing the following commands (as root). If you wish, instead of prefacing each command with sudo
, you can change into the root user by issuing the sudo -s
command.
First let's make sure all packages are fully up-to-date and you have the latest build tools...
sudo apt-get update sudo apt-get install build-essential automake checkinstall intltool git
For me, the above commands worked with no visible errors and the time taken was about five minutes. Once that is done, we need to install the Mono runtime.
sudo apt-get install mono-runtime
The above command worked with no errors and one warning. The elapsed time was about a minute. Now we can install the Mono package.
sudo apt-get install mono-complete git automake libtool
The above commands worked with no errors and the runtime was about 5 minutes.
At this point the Mono .NET runtime should be installed. You can test this by issuing the command mono -V
. If installed correctly, you should see the version display
as shown below
pi@raspberrypi:~ $ mono -V Mono JIT compiler version 3.2.8 (Debian 3.2.8+dfsg-10) Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com TLS: __thread SIGSEGV: normal Notifications: epoll Architecture: armel,vfp+hard Disabled: none Misc: softdebug LLVM: supported, not enabled. GC: sgen
You can also type the command mcs --about
on the command line to see if Mono C# compiler is there. On my system the command returned the following...
pi@raspberrypi:~ $ mcs --about The Mono C# compiler is Copyright 2001-2011, Novell, Inc. The compiler source code is released under the terms of the MIT X11 or GNU GPL licenses For more information on Mono, visit the project Web site http://www.mono-project.com The compiler was written by Miguel de Icaza, Ravi Pratap, Martin Baulig, Marek Safar, Raja R Harinath, Atushi Enomoto
Now we need to test things out. Below is some simple "Hello World" code. You can use the simple nano editor to create this (issue the command nano helloworld.cs
) by
copying the text below and pasting it in.
using System; namespace Hello { class HelloWorld { public static void Main(string[] args) { Console.WriteLine("Hello World!"); } } }
I compiled the above code with the command mcs helloworld.cs
and then ran it with the command mono helloworld.exe
. Note that
you can also issue the rather simpler command ./helloworld.exe
and the operating system will figure out that it is a .NET executable and automatically invoke
Mono for you. On my system all of the above code executed perfectly.
On some distributions you may install, by default, a much older version of Mono. For example, instead of the 3.2.8 version information above, the mono -V
command will return something like...
Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-5ubuntu2)...and if, as discussed in later steps, you try to implement remote debugging you will run straight into this bug . It's now been fixed but, simply put, remote debugging is not possible on earlier versions of Mono. You can install later versions of Mono and also upgrade an existing copy by following the instructions on this mono-project page.
If you have followed the steps above you will have seen that editing .cs
files on the Raspberry Pi is possible but perhaps not too user
friendly. There is a nice GUI development environment for Mono called MonoDevelop. The next step discusses how to
install MonoDevelop
on a remote Ubuntu Linux box and to configure it so that you can compile on that platform and the resulting exe
file is transported to the Raspberry Pi for execution.
The contents of this web page are provided "as is" without any warranty of any kind and without any claim to accuracy. Please be aware that the information provided may be out-of-date, incomplete, erroneous or simply unsuitable for your purposes. Any use you make of the information is entirely at your discretion and any consequences of that use are entirely your responsibility. All source code is provided under the terms of the MIT License.