Running ASP.NET 5 on Linux

I got ASP.NET vNext running on my Linux virtual machine. It was a little bit tricky but it’s not something hard. Just take some moments from your evening and I’m sure you will get everything running. This post introduces some tips and tricks how to make things work.

ASP.NET vNext running on Linux

If you go with clean installation like I did then you need to install Mono. I went with Ubuntu server 14 image on Windows Azure. If you have clean machine then you can install Mono by compiling it from sources but you can also install Mono using package manager. It’s important to have Mono 3.4.1 or later.

1. Accessing Ubuntu using Remote Desktop

As my Ubuntu runs on Windows Azure cloud and I will show this Linux also from my Surface RT I need some way to access Ubuntu using Remote Desktop. Here is the nice guide how to make Remote Desktop work with Ubuntu:

NB! You don’t need actually Remote Desktop if you don’t want to run browser in you Linux machine and you have also no other reasons to use desktop. If you prefer to have only shell access then it’s okay. To see web applications running on Linux you need later to open some ports maybe or use tunnel to Linux.

2. Install K Runtime

Run the following command in terminal:

curl https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.sh | sh && source ~/.kre/kvm/kvm.sh

This will install K Version Manager (KVM), K Runtime (KRE) and K Package Manager (KPM) you need to run ASP.NET vNext applications on you machine.

3. Install latest KRE

Now let’s install latest KRE. Run the following command in terminal:

kvm upgrade

This command calls KVM and asks it to download and install latest KRE.

4. Fix NuGet.config

It’s possible that NuGet has no idea about ASP.NET vNext package source. You can find NuGet.config from:

/home/<your username>/.config/NuGet

If it has only empty and closed configuration tag in it then modify contents to be like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="AspNetVNext" value=https://www.myget.org/F/aspnetmaster/ />
    <add key="NuGet.org" value="https://nuget.org/api/v2/" />
  </packageSources>
</configuration>

NB! We added ASP.NET vNext package source where published packages are held. If you want to play with raw stuff then use aspnetvnext instead of aspnetmaster.

6. Get your application from Git

Now you need to get source of some ASP.NET vNext application to your machine. Probably you are using Git. To download ASP.NET vNext sample applications you need to run the following command:

git clone https://github.com/aspnet/Home.git

7. Restore packages

In terminal move to root folder of your ASP.NET vNext application and restore packages it is using to run:

kpm restore

Now KPM restores all packages needed to run your application. This information is read from project.json files in your applications root folders.

8. Run your application

Now it’s time to run your application and see if it works:

k kestrel

This command calls KRE and tells it to use Kestrel as web server. As far as I know it’s currently the only server you can use on Linux out-of-box.

9. Fix Kestrel errors

If you get weird Kestrel errors then there is problem in Kestrel native assembly. To get rid of this problem read blog bost First Impression of .NET vNext by Carolyn Van Slyck. In the middle of page you can find section titled as Kestrel and there is also short guide how to replace the problematic file. To save you from building and fixing native lib Carolyn also provides compiled binary you can use.

After fixing run k kestrel again and now it should run without problems.

Gunnar Peipman

Gunnar Peipman is ASP.NET, Azure and SharePoint fan, Estonian Microsoft user group leader, blogger, conference speaker, teacher, and tech maniac. Since 2008 he is Microsoft MVP specialized on ASP.NET.

    2 thoughts on “Running ASP.NET 5 on Linux

    • March 5, 2015 at 5:54 pm
      Permalink

      This is all well and good from a “Hey look, it’s running on Linux!” proof-of-concept; are there any recommendations for how to run this in production? Kestrel back-end with nginx front-end? Or perhaps Kestrel in the back with Squid on the front?

    • March 27, 2015 at 12:28 am
      Permalink

      There are currently no recommendations and suggestions. It’s new situation and the world is waiting how it starts working. If you are one of those early birds eager to try things out first then you can try out different hosting scenarios.

    Leave a Reply

    Your email address will not be published. Required fields are marked *