Friday, 27 May 2016

Installing .Net Core on Ubuntu 16.04 LTS

The recent development by Microsoft in the ASP.Net core space is fascinating. With the introduction of ASP.Net Core 1.0 at the start of the year and then the recently released ASP.Net Core 1.0 RC2, I thought it would be a good idea to try it out on a Linux box.

The installation proved to be a bit trickier than I thought, so sharing my experience so as to help other out. The flavour of Linux I used was Ubuntu 16.04 LTS.

At the time of writing this post, the instructions present on Microsoft .Net Core website are for Ubuntu 14.04. Tried to follow the steps described on the website. However, execute dotnet failed with the following error on my machine
Failed to initialize CoreCLR, HRESULT: 0x80131500

So tried to proceed with some other steps. In general, installing .Net on Ubuntu require the following steps

1) Add .net repo to trusty sources list
2) Add key for the newly added trusted source
3) Install dotnet


To do the above, open up a terminal on your Ubuntu machine.

To add repo, run the following command
sudo sh -c 'echo "deb [arch=amd64] http://apt-mo.trafficmanager.net/repos/dotnet/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
To add the key, run the following command
sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
Once, the above done, it's bes to update everything by running
sudo apt-get update
 Now that everything is done, .Net can be installed by running
sudo apt-get install dotnet

The above command, however, didn't work for me. It failed with the following error


The following packages have unmet dependencies: dotnet : Depends: libicu52 (>= 52~m1-1~) but it is not installable E: Unable to correct problems, you have held broken packages.

The error is quite self-descriptive, and the answer is to install libicu package. Ran the commnad
sudo apt-get install libicu-dev

The above command installed the libicu55 on my machine, whilst .Net core has a dependency on libicu52. Fortunately, the package is available for download here.

Once downloaded, the package can be installed by running
sudo dpkg -i libicu52_52.1-3ubuntu0.4_amd64.deb 

Now that the pre-requisite is installed, installing dotnet is simply a matter of running the following
sudo apt-get install dotnet

The above worked for me this time around. To test that it installed correctly, just type dotnet new in a new folder. It will create files for your .net project.

Please Note: Make sure that you set permissions to execute downloaded files described in this post. 

5 comments:

paul_ogle said...

shouldn't it be sudo dpkg -i to install the .deb package? Other than that, great tutorial!

Hamid said...

Yes you are right Paul. Thanks for correcting. I will edit the post.

johnny serup said...

This did not work for me on Ubuntu 16.04 LTS 64bit
it resulted in multiple unhandled exceptions - even after trying uninstall of old

Why are you using trusty when, I think 16.04 is xenial ??

Dileep.M said...

I'm trying to install on 16.04, i386 .

Getting following exception Please help.


Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package dotnet-dev-1.0.0-preview1-00270
E: Couldn't find any package by glob 'dotnet-dev-1.0.0-preview1-00270'
E: Couldn't find any package by regex 'dotnet-dev-1.0.0-preview1-00270'

isabellaJoseph said...

Thanks for this blog. Provided great information. All the details are explained clearly with the great explanation. Learn.. Dot Net Training in Chennai
Selenium Training in Chennai
Hadoop Training in Chennai