Running ASP.NET 5 application on Linux

In this article we will get to know how to run ASP.NET 5 application on Linux.

Before getting in to ASP.NET 5 part, let’s get familiarize with below basic commands which will help you on your Linux boxes

 Command

 Description

 more, less, cat, tail, tail -f

 View the contents of a file

 vi, vim, nano

 Edit a file

 cp, mv

 Copy and move files

 df –h, du -h

 Check disk space utilization

 ls, ls -ltr

 List files

 uptime, w, top

 Check system uptime

 sudo su

 Gain super-user privilieges

 ps , ps –l

 Process listing

 Lsof

 Look at process open files and ports

 ip addr show / ifconfig

 Verify network adapter configuration

 Netstat

 Network information

 man

 Help on a command

 ip route, route, netstat –r

 View Routing Table        

 netstat -rn, route -n

 Default Gateway

 iptables --list

 View Firewall rules

 ip -s link show eth0 , netstat -s

 Network Statistics

 

Folder structure in Linux and its explanation

 Folder Structure

 Explanation

 /

 Root Directory where everything is located under this and similar to C:\ in Windows.

 /bin

 Contains system specific binaries and executables.

 /boot

 Contains files required to boot your machine.

 /dev 

 Contains files which is used by hardware.

 /etc

 Contains configuration files for your programs.

 /home

 Contains a home directory for each user.

 /lib

 Contains shared libraries.

 /lost+found

 Contains recovered files

 /root

 Home folder for root.

 /media

 Contains folders for media attached like CDs,USBs.

 /sbin

 Contains programs which is run by root.

 /proc

 Contains kernel and process files.

 /tmp

 Contains temporary files stored by application.

 /usr

 Contains application and files by users which are read only

 /var 

 Variable data writable directory.

               

Steps to get ASP.NET 5 on Ubuntu

  • Install DNVM
  • Install DNX
  • Install Libuv
  • Install git
  • Download ASP.NET Sample
  • Run dnx web

Installing .NET Version Manager(DNVM)

  • Install and unzip curl if you have not installed:

 sudo apt-get install unzip curl

  • Download and install DNVM:

 curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source  ~/.dnx/dnvm/dnvm.sh

 Once you run above command you should be able to run dnvm commands like “dnvm list”.

Installing .NET Execution Environment (DNX) for .NET Core

  • Install DNX Pre-requisites:

 sudo apt-get install libunwind8 gettext libssl-dev libcurl4-openssl-dev zlib1g libicu-dev uuid-dev

  • Install DNX for .NET Core using DNVM:

 dnvm upgrade -r coreclr

 

Installing Libuv

Libuv is a multi-platform asynchronous IO library that is used by Kestrel, a cross-platform HTTP server for hosting ASP.NET 5 web applications.

To build Libuv run the below commands one after the other:

 sudo apt-get install make automake libtool curl

 curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | sudo tar zxfv - -C /usr/local/src

 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

Make sure libuv.so.1 is there under /usr/local/lib after you run above commands.

For now, we have .NET core setup and below steps will help you to download sample ASP.NET 5 application from Git

 

Install Git

Run below command to install git:

 sudo apt-get install git

 

Download ASP.NET 5 Sample from Git

Run the below command to clone ASP.NET 5 application from git:

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

Run DNX Command

Navigate to the directory where the application is installed and in my above example it would have installed 3 applications “ConsoleApp”, “HelloMvc” and “HelloWeb”.

Run below command to execute the “ConsoleApp” application:

 dnu restore

 

 dnx run

 

Note: In case you run into an issue where you get error as:

 Restore failed

 Access to the path ‘/home/<user>/Home/Sample/…/ConsoleApp/project.locl.json’ is denied.

when you run “dnu restore” command then you need to check the permission on the application directory level. In my case I ran into this issue and ran below command at application directory level to give full permission.

 sudo chmod 777 <foldername>