How to setup .NET Core 2 on Debian or Ubuntu Linux distro the easy way
Installing .NET Core on Linux the short way
Many of you who had chance to work docker and .NET Cote on Linux will agree that easiest way of running .NET Core on Linux is to pull microsoft/aspnetcore:2.0 image from docker repository and just setup your app with .Dockerfile.
You will be saved of the hassle of setting up the environment and .NET Core on on the Linux machine. But what if that is not an option? What if you really need for some reason to run your application on the specific host and not in the container?
In this case you have to prepare yourself of not so easy setup of .NET Core on your Debian or Ubuntu machine. Internet is full of articles and questions on how to setup .NET Core on Linux and I can undersgan why. I actually figured that out when I wanted to setup .NET Core on Ubuntu server to test my .NET Core daemon project. It was a headache :(
I tried to follow steps explained on https://www.microsoft.com/net/download/linux-package-manager/ubuntu14-04/sdk-current but it did not go that smooth. I kept getting different and different error messages as soon as I fixed the previous one.
But in the end I managed to set it up, so I wanted to share the exact steps how did I make it work for me. So let's start.
This method of setup of .NET Core was done on Ubuntu server 14.04 but it should work on other Ubuntu/Debian version. If you have any issues please post the question at the bottom of the article.
First visit https://www.microsoft.com/net/download/thank-you/dotnet-sdk-2.0.3-linux-x64-binaries to download the .NET Core 2 SDK binary. If you are opening this in a browser, download should start automatically. In case you want to download directly from the command line execute these lines
mkdir $HOME/dotnet cd $HOME/dotnet wget https://download.microsoft.com/download/D/7/2/D725E47F-A4F1-4285-8935-A91AE2FCC06A/dotnet-sdk-2.0.3-linux-x64.tar.gz
This will create dotnet folder in your home folder and download .NET Core 2 binaries package. Once download is finished extract downloaded archive in the same folder.
tar zxf dotnet-sdk-2.0.3-linux-x64.tar.gz
Update the PATH environment variable to point to dotnet folder as well
Last step to make dotnet core working is installing libunwind-dev package
sudo apt-get install -y libunwind-dev sudo apt-get install libunwind8 icu-devtools
Try to see if dotnet is working
With export command we set PATH environment variable only for the current session. To have it saved permanently you need to add PATH value in your bash profile file
sudo nano $HOME/.bash_profile
if file is not empty, navigate to the end of the file and add the following value
In case file is empty add the following value and save file
To verify, reboot your Linux machine
sudo reboot -h now
Once your machine restarts, login and check if dotnet is recognized as a command
You are ready to publish your application from Visual Studio and run then on your Linux machine.
Purpose of the code contained in snippets or available for download in this article is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage.
Comments for this article