install .NET on Ubuntu

How to install .NET on Ubuntu Linux?

How To - A help section for how to do a task

Install .NET on Ubuntu

Let’s learn how to install .NET on Ubuntu Linux on different versions of Ubuntu. In the first step, we will register the trusted Microsoft signature key by using the following commands:

~$ curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
~$ sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg

Now register the Microsoft Product feed on Ubuntu 17.10 by using the following commands:

~$ sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-artful-prod artful main" > /etc/apt/sources.list.d/dotnetdev.list'

Now register the Microsoft Product feed on Ubuntu 17.04 by using the following commands:

~$ sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-zesty-prod zesty main" > /etc/apt/sources.list.d/dotnetdev.list'

Now register the Microsoft Product feed on Ubuntu 16.04 / Linux Mint 18 by using the following commands:

 ~$ sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'

Now register the Microsoft Product feed on Ubuntu 14.04 / Linux Mint 17 by using the following commands:

 ~$ sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-trusty-prod trusty main" > /etc/apt/sources.list.d/dotnetdev.list'

Now you can proceed to install & run the .NET SDK.

Open your terminal or command prompt and execute the following commands to update the products available for installation:

~$ sudo apt-get update
~$ sudo apt-get install dotnet-sdk-2.0.2

Now you have to create your app. Close the command prompt and reopen it. Now, type the following commands:

~$ dotnet new console -o myApp
~$ cd myApp

The dotnet command will create the new app of console type. The -o parameter will create new folder or directory naming it myApp. Your app and its files will be stored here. To navigate to newly created folder myApp, you will use cd myApp command. There will be a file Program.cs in myApp folder which contains hello world code.

using System;

namespace myApp

{

class Program{

static void Main(string[] args){

Console.WriteLine("Hello World");

}

}

}

 

Now its time to run your app. To run your app, open your command prompt or terminal and write the following command and press enter to execute.

~$ dotnet run

 

Thanks for reading our tutorial. Check more!

Leave a Reply

Your email address will not be published. Required fields are marked *