Building Asp.Net Mvc 6 on Ubuntu 16 LTS

Building Asp.Net Mvc 6 on Ubuntu 16 LTS

  • 2016-08-20
  • 2435

I thought I would make my first blog entry in a while on something I have been realizing as of late, that is .Net Core, all the more particularly on Ubuntu 14.

To start with things to start with, open a terminal! Actually I run every one of these orders under the root client, so I will utilize ‘sudo su’ with the goal that I don’t need to enter sudo each time I require super client benefits (so if you don’t you will need sudo in front of almost all of the commands). I have likewise found that occasionally the permisions between the root client and the neighborhood client can bring about issues on the off chance that you don’t introduce everything against ONE client. In the event that you utilize ‘sudo su’ you will need to utilize the root represent all that you introduce through apt-get, yet you will at present need to run the bundles you introduce by means of npm under your record as root won’t have entry (this is important for Yeoman)

Installing .Net Core

The accompanying will walk you through the preperation of your framework

Installing DNVM

The following stride is to enter a few orders that will permit us to download and introduce DNVM. DNVM remains for Dot Net Version Manager and is the instrument used to set and deal with the .net run-times on your machine. For more data look at the aspnet documentation on DNVM.

          ~$ sudo su
          ~$ 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

In the wake of doing the above orders you can test that the establishment worked by writing “dnvm”

enter image description here

In the event that you don’t see the above once you have entered the above orders then search for mistake messages as well as attempt to enter the summon ‘source ~/.dnx/dnvm/dnvm.sh’. This ought to run naturally however. In the event that you might want to discover more about the dnvm you can likewise sort ‘dnvm - h’ to raise the assistance.

Installing DNX and Core CLR

The accompanying summons will download the essentials of the dnx and afterward introduce the Core CLR. The center CLR is the new open source usage of .net which has been developed starting from the earliest stage be utilized to construct .net applications cross stage and has been cloud advanced. It is light weight and exceptionally uncoupled. Not at all like .net 4 and mono, it is introduced per application as opposed to per framework, this per application outline is incredible as it will permit devs later on to put in new applications to their servers without upgrading all their old applications and without the framework administrators info!

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

The primary line introduces the essentials and the second educates the dnvm to either introduce the most recent coreclr or to overhaul to the most recent, you MUST incorporate ‘- r coreclr’ as it teaches the dnvm you would prefer not to update the default mono clr. It is at ths time that you could likewise introduce mono, yet I have picked not very as this blog entry is about the center clr.

To verify that you have the core clr installed and to check what runtime is active, type ‘dnvm list’

enter image description here

Two things to note:

  1. Active: shows you which run time is currently in use.
  2. Alias: When you upgrade the default alias is automatically added, if you have multiple run times you can utilize the ‘dnvm use’ command with ‘-p’ to switch the active run time and to remove the current default alias and set it to the newly selected one.

Installing Kestrel requirements

When we in the long run make a MVC 6 site, we will require somthing to run it! So I have picked to utilize the default web server that .net center is given, Kestral.

To run Kestral, we will need to install libuv, a multi-platform asynchronous IO library!

         ~$ 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
          ~$ sh autogen.sh
          ~$ ./configure
          ~$ make
          ~$ make install
          ~$ rm -rf /usr/local/src/libuv-1.8.0 && cd ~/
          ~$ ldconfig

The above installs libtool and curl, then downloads the libuv source, configures it, compiles it and finally installs it. ldconfig is used to update the ld.so.cache so that dlopen can load it.

Congratulations! You now have a working .net environment on your system! What’s next? Actually making something!

MVC 6 with YeoMan scaffolding!

To use YeoMan to scaffold the default project that we have all grown to love from Visual Studio, we first will need to install a few things, namely node, npm, yo and generator-aspnet!

Installing Node.js and NPM

installing node is simple enough, there are just a few apt-get to run and your good!

          ~$ apt-get install nodejs
          ~$ apt-get install npm
          ~$ ln -s /usr/bin/nodejs /usr/bin/node

What it does is fairly self explanitory, install the nodejs and npm, then add a symbolic link for node so we can use node in the terminal. From here we can enter ‘node -v’ and ‘npm -v’ to confirm installation.

enter image description here

Updating NodeJs

The next is optional, but if your system already has nodejs installed making sure you have the latest version of nodejs is a good idea!

          ~$ npm cache clean -f
          ~$ npm install -g n
          ~$ n stable

This will clean out the npm cache and the next line installs the n package (node helper) globally (-g). From there we run n stable to tell the node helper to update to the latest stable release. You could also enter a specific version you want to use instead of stable. Next when you type you will find your node is up to date!

Installing YeoMan and the aspnet generators

Almost on the home stretch now! All that is left is to install YeoMan and the aspnet generators

          ~$ npm install -g yo
          ~$ npm install -g generator-aspnet

This will install YeoMan and the aspnet YeoMan Generators globally.

Scaffolding the MVC Starter Template

All that is left now is to actually run the YeoMan aspnet gernerator! Today we will be creating the default MVC Web Template that you make when you choose the default authentication in Visual Studio.

First type ‘yo aspnet’ into the console. You will be presented with an error! Oh no! Don’t worry, if you see this there is a good chance it is because you are still under the root account and you just need to type ‘exit’ to go back to your users session. I don’t know why ‘yo’ won’t work for me under the root account, but the fix is easy enough. Try again and this time you will be presented with the following (after choosing to contribute your data or not):

enter image description here

From here you can use your arrow keys to navigate the menu, choose Web Application.

Then choose a nice name (I will be using ‘HelloMvcUbuntu’).

All that is left to do is follow the instructions it leaves you. If you ran the installation under the root (sudo su) account you will need to login to the super user account again (type ‘sudo su’)

        ~$ cd "HelloMvcUbuntu"
          ~$ dnu restore 
          ~$ dnu build (optional, build will also happen when it's run)
          ~$ dnx web

this will move you into the newly created directory and restore all of the nuget packages that are required as documented inside of project.json. If you want to have a look around the directory either use ‘ls’ and ‘cd’ OR you can use ‘xdg-open .’ to open the current directory in the Ubuntu file explorer.

If you want to be able to run ‘dnu build’ you will need to make a modification to project.json. Inside of the frameworks you will see there is ‘dnx451’ which is actually only available on windows, so you can either remove it or add mono in there if you have it installed.

After running all of those commands congrats! your website running in aspnet is now running on http://localhost:5000.

enter image description here

Just as a heads up, in the next release candidate (rc2) and all the future versions the two commands dnu and dnx are merging into the single tool command ‘dotnet’ so instead of the above commands you would use:

          ~$ cd "HelloMvcUbuntu"
          ~$ dotnet restore 
          ~$ dotnet build (optional, build will also happen when it's run)
          ~$ dotnet web

I hope this helps somebody out there, if you have any questions or feedback please feel free to leave them in the comments bellow.

Suggest

ASP NET Core (ASP NET 5),MVC 6,C#,Angular2 & EF Crash Course

REST WCF Service in ASP.NET

Complete ASP NET MVC Web Development - Newbie to Ninja!

Learn ASP NET with Bootstrap, Entity Framework, JavaScript, C#

Mastering ASP.NET and ADO.NET with C#