Getting Started with ASP.NET 5 for OS X, Linux, and Windows (2015)
3 Deploying ASP.NET 5 on Linux
In this chapter we will learn how to deploy ASP.NET 5 on Linux.
3.1 Getting Started
In this section we start to deploy ASP.NET 5 on Linux. In this book I use ASP.NET 5 preview, beta4. For illustration, I use Ubuntu 15.04 as Linux distro. Please follow installation steps on next section.
3.2 Deploying ASP.NET 5
This installation process is based on this documentation, https://github.com/aspnet/Home/blob/dev/GettingStartedDeb.md . In this section, we install ASP.NET 5 on Linux manually (without docker). Firstly, you update your distro.
$ sudo apt-get update
In general, to install ASP.NET 5 on Ubuntu, you can do the following steps:
· Installing Mono
· Installing libuv
· Installing DNVM
· Installing git (optional)
3.2.1 Installing Mono
Mono is .NET runtime for Linux. You need the latest version of Mono runtime. To install it, you can type these commands.
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
$ echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
$ sudo apt-get update
$ sudo apt-get install mono-complete
If finished, you can verify it by checking its version.
$ mono --version
3.2.2 Installing libuv
Libuv is a multi-platform asynchronous IO library that is used by the KestrelHttpServer that we will use to host our web applications.
Type these commands to install libuv library.
$ sudo apt-get install 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
3.2.3 Installing DNVM
The last step is to install DNVM. Type this command.
$ curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
If success, you can see a task which you should do. We must add dnvm on our profile.
Type this command.
$ nano /home/<account>/.bashrc
Please change <account> by your Linux login account.
Then, you get nano editor. You also edit this file using gedit or other text editor. Add this script on .bashrc file into your profile, for instance, /home/<account>/.bashrc .
Then, type this script.
source /home/<account>/.dnx/dnvm/dnvm.sh
Please change <account> by your Linux login account.
If done, save this file. After that, close your Terminal and then open again so Terminal will load profile script.
The next step is to upgrade. Type this command.
$ dnvm upgrade
Now you already installed dnvm. It will be used to manage ASP.NET 5 runtime on Linux. You can verify dnvm by typing this command.
$ dnvm help
So you see a list of dnvm parameter.
You can also see a list of your DNX runtime by typing this command.
$ dnvm list
3.2.4 Installing git
This task is optional but I recommend to install it because we want to run the sample app from https://github.com/aspnet/Home .
Type this command to install git.
$ sudo apt-get install git
3.3 Testing
To test our ASP.NET 5, we use code samples from https://github.com/aspnet/Home . We clone this code samples and then restore all required libraries using dnu command.
Type these commands.
$ git clone https://github.com/aspnet/Home
$ cd Home
$ dnu restore
Now you are ready to run code samples.
3.3.1 ASP.NET Console
To run ASP.NET Console, we can use dnx. Firstly, navigate to ConsoleApp project.
Type these commands.
$ cd samples/latest/ConsoleApp/
$ dnx . run .
If success, you can see a message "Hello World" on Terminal.
3.3.2 ASP.NET 5
To run ASP.NET 5 app, we can use dnx with kestrel. Firstly, navigate to HelloWeb project.
Type these commands.
$ cd samples/latest/HelloWeb/
$ dnx . kestrel
Now open a browser and then navigate to http://localhost:5004/ . You should see ASP.NET 5 app.
To stop kestrel, you can type exit.
exit
3.3.3 ASP.NET MVC
To run ASP.NET MVC, we can use dnx. Firstly, navigate to HelloMvc project.
Type these commands.
$ cd samples/latest/HelloMvc/
$ dnx . kestrel
Now open a browser and then navigate to http://localhost:5004/ . You should see ASP.NET MVC app.
To stop kestrel, you can type exit.
3.4 Development Tools
The next step is to build program. To write a program, you can use any text editor. Microsoft also provides Visual Studio Code. It runs on Windows, Linux and Mac. You can download it on https://code.visualstudio.com/ .