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 (plus Windows and Mac). For starters, I tried to get the KesteralHttpServer sample application working which wasn’t too easy, so this post takes you through it step by step.
Join the DZone community and get the full member experience.Join For Free
Being both a long-time .NET developer and Linux hobbyist, I was very excited about the recent "go live" announcement for CoreCLR on Linux (plus 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 to take.
So, first create a new Ubuntu Server 14.04 AMI:
With a t2.micro instance type:
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 I'd installed 1.0.0-rc2-16357.
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:
There’s obviously a ways 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.
Published at DZone with permission of Mike Hadlow, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.