Posted by: lluppes | March 19, 2015

Installing Mono and ASP.NET on a Raspberry Pi

In my previous post, I detailed how to get a Raspberry Pi up and running and ready for some serious .NET development.

I broke this down into two blog posts because doing it justice in one makes it two long:

Part 1 – A Beginner’s Guide to setting up your Raspberry Pi
Part 2 – Installing Mono and ASP.NET vNext on your Raspberry Pi (this post)

<TL;DR>    (a.k.a.  Too Long – Didn’t Read!)

These scripts are available on
A free eBook with all this info and more is available at

To use these script files, first fetch the first master file from the repository by entering a wget command in the command line window on your Pi.  At this point you will have a file, but the operating system doesn’t know that it’s a script, so you have to go tell it to give the file execute permissions by running the “chmod” command. Finally, run that command file using the “sh”, which will in turn fetch the other files and automatically mark them as executable.

chmod 755 getScripts
sh getScripts



Installing Mono (the wrong way)

Installing Mono seems to be (almost) as simple as running the following command:

sudo apt-get mono-complete

If you do that, check the version number by executing this command

mono --version

However… this will get you version 3.2.8, which is definitely not the latest.  If you use this, you will get a partially working Mono that will work for very simple programs and crash when you do something really complex like try to put a textbox on a screen.

Installing Mono (the right way)

Installing the latest Mono isn’t quite as intuitive as the previous way of doing it.  You need a few configurations first.  The following steps will load the latest build of Mono on your Pi:

sudo apt-key adv --keyserver --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mono-complete


You can do this automatically:

chmod 755 3_install_mono
sh 3_install_mono

When you are done, check the version number with this command, and you should see a 3.12* version:

mono –version


Running a C# WinForms Program

Running a Windows Forms application on a Pi (or Console App) is actually very simple.

  • Create and compile a Windows Forms App
  • Use WinSCP to copy the files from your bin folder to the Pi
    • Create a directory on the Pi to hold your files
    • Copy the EXE and any referenced DLL’s
    • You don’t need the .XML or .PDB files or the vshost.* files
  • Switch over to the Pi and double click to run the program
  • Voila – it should just work!

I’ve tested this with a fairly simple forms program that had dialogs, file IO, etc., and had no problems.  That’s about as far as I’ve explored so far.  I’ll update this with more info later as I experiment more with this.

Installing ASP.NET vNext

One of the awesome features of the new version of ASP.NET v5 is that it’s designed to run on many operating systems, including on a Mac and Linux.  However, there are a couple of pieces that you need to install in order to make your new ASP.NET vNext pages work – primarily the KVM and Libuv modules.

Update Your Certificates

In order to get those programs installed properly, you’ll need some updated certificate.  Update the certificates on your Pi with these commands.  You’ll be prompted multiple times to confirm the certificates, and they will warn you that they certs are invalid (don’t believe it!).  Just say “Y” to each certificate and you should have no problems with this.

sudo certmgr -ssl -m
sudo certmgr -ssl -m
sudo certmgr -ssl -m
sudo certmgr -ssl -m
mozroots --import --sync

You can do this automatically:

chmod 755 4_install_certs
sh 4_install_certs

Install KVM

To install KVM (the kernel Virtual Machine) use these commands:

mkdir ~/sources/
mkdir ~/sources/aspnet5
cd ~/sources/aspnet5
git clone git://
sh ~/sources/aspnet5/home/
echo "  Run this command:      source /home/pi/.k/kvm/"
echo "  Then run this command: kvm upgrade"

I’m not sure why, but the last two commands fail when I try to include and run them in this batch file, so I had to run them manually…

You can do this automatically:

chmod 755 5_install_kvm
sh 5_install_kvm

Install Libuv

Libuv is a cross-platform support library which was originally written for NodeJS, designed around the event-driven asynchronous I/O model.  Install it using these commands:

tar -xvf libuv-v1.0.0-rc1.tar.gz
cd libuv-v1.0.0-rc1/
./ -f make -Duv_library=shared_library
make -C out
sudo cp out/Debug/ /usr/lib/
sudo ln -s /usr/lib/

You can do this automatically:

chmod 755 6_install_libuv
sh 6_install_libuv

Running Your First ASP.NET MVC6 Page

After installing and configuring the app, run these commands:

cd /home/pi/sources/aspnet5/home/samples/HelloMvc
kpm restore
k kestrel

The unset RUNLEVEL command is there because I keep getting the error “System.ArgumentException: An element with the same key already exists in the dictionary”.  If you run the command “printenv” you’ll see that you have two rows that say runlevel=.  The command “unset RUNLEVEL” will remove the second one, then you can run the k kestrel command and it should work. There must be a way to get rid of this, but I haven’t found it yet!

If everything worked and was installed properly, you should see the word “Started” in your command window.  Open a browser and navigate to http://localhost:5004/ and you should see the default welcome screen.


To replace the welcome screen with the more typical index page, you have to add a route in the startup.cs.  Edit the HelloMVC/startup.cs and comment out the UseMvc() line and add a new route:

app.UseMvc(routes =>
    name: "default",
    template: "{controller=Home}/{action=Index}/{id?}");

If you want some customized content, edit the HelloMVC HomeController.cs to have User.Name equal to your name.

User user = new User() {
    Name = "Lyle",
    Address = My address"

Go back to your command window and hit Ctl-Z to stop the process.  It’s stopped but actually still running so you will need to type in the command “kill %1” to really kill it.  Once it’s gone, type in “k kestrel” command to restart it and then refresh your browser, and you should end up with something like this:



In Conclusion

I hope this walk through helped you out.  I had a hard time finding all the right details for this – there were little bits and pieces everywhere and allusions to some of this, but nothing comprehensive that put it all together.

I’ll be adding more to this in the near future as I get more content about how you can create a fully working ASP.NET vNext / MVC6 application running, and a working sample project you can download from the GitHub repository.

You can download a free eBook with all this info and more at:




  1. […] Part 2 of this series will detail how to properly install Mono on your Pi, and then get some .NET programs running, and how to configure and run ASP.NET vNext. […]

  2. Thank you for this info.It’s ver useful.

    Do you know if I can apply this info in my raspberry pi 3?

    I’d like to install,mono and apache in my raspberry pi 3

    Thanks a lot

    • I would think so. I’ve been planning to do this myself as I have an RPI3 that I want to put mono on. I’m guessing the version numbers have changed, but the process should be the same.

  3. Hello, having issues installing libuv following your instructions. Getting “You need to install gyp in build/gyp first”. Any ideas?

    • I know that has changed a lot since I published this a year ago. I haven’t tried it with the new version yet, so I’m not sure what to tell you about gyp. Sorry!

    • I had that problem too, try entering “sudo apt-get install gyp” and that should resolve that issue, or at least I did that and could continue without problems.

  4. It seem that “deb wheezy main” is not works anymore on my rPI2.

    Please see mono 4 installation in this thread…

    • Sorry about that — this post hasn’t been updated in while and the Raspbian version has changed. I should probably mark this as obsolete or update it, but haven’t had time.

What do you think?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: