17 Dec Installing and running ASP.NET 5 (vNext) on Linux with thick Windows goggles
This blog post will walk you through the installation of ASP.NET 5 (vNext) on Linux (Ubuntu 14.04) from my perspecitve, which is through thick Windows eyes. When the installation is complete I’ll create a very simple application using Yeoman. For you who just want to get going with the installation without reading, see the TLDR; section below. Also, if you already have everything installed and just want to create an application you can jump to create your application.
Microsoft already have a great walkthrough @ http://docs.asp.net/en/latest/getting-started/installing-on-linux.html or you can use my own script that will install everything needed for you in a blink. To do that run the following command:
curl -sSL https://raw.githubusercontent.com/Hagsten/aspnet-complete-install/master/install.sh -o install.sh && bash install.sh && rm install.sh
I’ve really gotten my eyes up for Linux recently, and it is all because of Microsoft. Linux users will probably go ‘ugh’ reading that, but everyone has to start somewhere.
The reason for my recent Linux interest spells ASP.NET 5 (which might be obvious to you) which enables us to write and host ASP.NET applications on Linux. This is something that has not been possible since the dawn of .NET (we could, using Mono, but that is a story for another day).
As the title infers, I am a Linux rookie and I’ve recently installed it for the sole purpose of trying out ASP.NET 5 on it, but I’m growing quite fond of it so I might use it for other purposes in the future.
When reading the official Microsoft walkthrough on installing .NET 5 I can see that there are many pre-requisites and dependencies to install DNVM and DNX. Instead of just installing everything blindly, I searched the web for information about each dependency to really get a grip on what is actually going on (and at the same time learn some Linux lingo). I though I’d share it to you. So, here is my version of Microsofts walkthrough, complete with information on each dependency and (most) Linux terms that are used.
Install .NET on Linux
.NET Core have many dependencies and prerequisites, we have its own components such as DNVM and DNX which in turn depends on other libs. If you are, as me, a rookie at Linux, there are a few commands that are vital to understand:
- sudo: Basically run as admin. You will be promted to input your credentials before the command is executed.
- apt-get: A package manager tool where you can install software from a centralized software center (command: apt-get install).
Before we start we need to download curl which is a client for downloading/uploading files from a server. It supports HTTP, HTTPS, FTP, etc.
To install curl, run:
sudo apt-get install unzip curl
Dot Net Version Manager (https://github.com/aspnet/dnvm). This tool will install and manage your dnxcore version. To install it, run this command:
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
Run "dnvm" to verify the installation.
DotNet eXecution environment. DNX is used to build and run your .NET applications.
A library to determine the call-chain of a program.
A framework for producing multilingual messages. In essence, this utility provides the possibility to give the user messages (error messages, info messages, etc…) in their native tounge.
A package that is a part of the OpenSSL implementation. OpenSSL is a open source project that aims to implement the SSL protocol (among other) with a commercial grade quality.
More OpenSSL stuff. Documentation and development files.
This library have to do with compression. It implements, among others, GZip.
Unicode and locale support.
Univerally unique Id
sudo apt-get install libunwind8 gettext libssl-dev libcurl4-openssl-dev zlib1g libicu-dev uuid-dev dnvm upgrade -r coreclr
Run ”dnx” to verify the installation.
Kestrel (a cross-platform HTTP server for hosting ASP.NET 5 web applications) is based on libuv, so it is a vital component in enabling .NET on Linux. Libuv is a cross-platform asyncronous IO library.
Installing Libuv is not a simple as the other libs which could be installed using apt-get, instead we must build our own version of it using ”make” (how Linuxy!).
First we need to install automake which is a tool to automatically generate makefiles. Makefiles are important since it describes how to build software from its source files. Then we need to install libtool which is a utility to simplify the makefile. Finally, curl is needed. If you followed this blog from the top, you should already have it installed.
sudo apt-get install make automake libtool curl
Then we need to download the compressed source code using
and when it is done we pipe to unpack these files to /usr/local/src.
curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | sudo tar zxfv - -C /usr/local/src
Finally we build libuv using ”make” and then some post build cleanup.
cd /usr/local/src/libuv-1.4.2 sudo sh autogen.sh sudo ./configure sudo make sudo make install sudo rm -rf /usr/local/src/libuv-1.4.2 && cd ~/ sudo ldconfig
Creating your application
To aid us in creating our very first .NET application on Linux we will use a tool called Yeoman which is a project scaffolding tool. You will be needing npm since we will be installing Yeoman through npm. First it can be a good idea to update your local package list so that you get the newest version of node.
To update the package list and then install npm:
sudo apt-get update sudo apt-get install nodejs npm
To install Yeoman
sudo npm install -g yo
Yeoman should now be installed and we can run ”yo aspnet”, this will start a Wizard where you can choose which kind of project you want (just like the ones you get in Visual Studio). Choose Web Application (or anything you like).
Then you are asked to input the application name, enter one and press enter.
Yeoman will now create the same folder structure (with files) as one are used to when working with Visual Studio, it will also give you some help getting up and running.
If we follow Yeomans instructions at the bottom we should have a server listening to requests at port 5000 (if you selected Console application you can run the command dnx run instead of web). Try it out by navigating to http://localhost:5000.
There you have it, ASP.NET built and running on Linux.