Thursday, January 14, 2016

Running The KestrelHttpServer On Linux With CoreCLR

Being both a long-time .NET developer and Linux hobbyist, I was very excited about the recent ‘go live’ announcement for CoreCLR on Linux (and Windows and Mac). I thought I’d have a play with a little web server experiment on an Amazon EC2 instance. To start with I tried to get the KesteralHttpServer sample application working which wasn’t as easy as I’d hoped, so this post is a note of the steps you currently need.

So first create a new Ubuntu Server 14.04 AMI:

image[5]

With a t2.micro instance type:

image[11]

Next log in and update:

ssh -i .ssh/mykey.pem ubuntu@-the-ip-address
...
sudo apt-get update
sudo apt-get upgrade

Currently there are two different sets of instructions for installing CoreCLR on Linux. The first one I found (I think linked from Scott Hanselman’s blog) shows how to use the standard Debian package manager to install the new ‘dotnet’ comand line tool. Apparently Kestrel will not currently work with this. The second set of instructions use the existing ‘dnvm’, ‘dnu’ and ‘dnx’ tools. These do work, but you need to get the latest unstable RC2 version of CoreCLR, like this:

First install the Dot Net Version Manager tool:

sudo apt-get install unzip curl
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
source /home/ubuntu/.dnx/dnvm/dnvm.sh

Next install the latest unstable (thus the '-u' flag) CoreCLR:

sudo apt-get install libunwind8 gettext libssl-dev libcurl4-openssl-dev zlib1g libicu-dev uuid-dev
dnvm upgrade -u -r coreclr

At the time of writing this installed 1.0.0-rc2-16357

image[17]

You also need to follow the instructions to build the libuv library from source. This sounds hairy, but it worked fine for me:

sudo apt-get install make automake libtool curl
curl -sSL https://github.com/libuv/libuv/archive/v1.8.0.tar.gz | sudo tar zxfv - -C /usr/local/src
cd /usr/local/src/libuv-1.8.0
sudo sh autogen.sh
sudo ./configure
sudo make
sudo make install
sudo rm -rf /usr/local/src/libuv-1.8.0 && cd ~/
sudo ldconfig

Next get the KestrelHttpServer source code:

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

Restore the Kestrel packages by running dnu restore in the root of the repository:

cd KestrelHttpServer
dnu restore

Next navigate to the sample app and restore the packages there too:

cd samples/SampleApp/
dnu restore

Now you should be able to run the sample app by typing:

dnx web

image[23]

Voilà!

There’s obviously some way to go before this is a straightforward out-of-the-box experience. The team should also try and unify their getting started instructions because there are various different conflicting pages floating around. The Kestrel team were very helpful though in getting this working. Now to do something with my new found Linux web server.

3 comments:

  1. great post!

    Not sure if you have seen this but I found this very straight forward for ubuntu setup: http://docs.asp.net/en/latest/getting-started/installing-on-linux.html

    ReplyDelete
  2. Great stuff as usual Mike.

    I would not try to rm -rf ... && cd ~/ on the same line. This seems like a recipe for disaster.

    ReplyDelete
  3. Thanks for sharing. This is really informative and handy example of how to start with core 1.0



    ReplyDelete

Note: only a member of this blog may post a comment.