Setting Up Dotnet core on ubuntu

Oluwasegun Haziz
4 min readMay 25, 2019

--

google.com

Writing Hello World! In any programming language is the first step to becoming a Ninja. This tutorial is going to show us how to write Hello World using Dotnet core on Ubuntu, a distribution of the Linux Operating System.

To get started, we need the following:

  1. Ubuntu( I use Ubuntu 18.04)
  2. Visual Studio Code

The following are 10 steps I took in installing dotnet core on my Ubuntu.

  1. Open your terminal
  2. We need to register the Microsoft product repository and install the required dependencies. This need to be done once per machine.
$ wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb$ sudo dpkg -i packages-microsoft-prod.deb

3. Update the products available for installation, then install the .NET SDK.

$ sudo add-apt-repository universe$ sudo apt-get install apt-transport-https$ sudo apt-get update$ sudo apt-get install dotnet-sdk-2.2

4. If you receive an error message similar to “Unable to locate package dotnet-sdk-2.2”, run the following commands( Note that mine installed without errors).

$ sudo dpkg — purge packages-microsoft-prod && sudo dpkg -i packages-microsoft-prod.deb$ sudo apt-get update$ sudo apt-get install dotnet-sdk-2.2

Else

If that doesn’t work, you will have to run a manual install with the following commands.

$ sudo apt-get install -y gpg$ wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg — dearmor > microsoft.asc.gpg$ sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/$ wget-q https://packages.microsoft.com/config/ubuntu/18.04/prod.list$ sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list$ sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg$ sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list$ sudo apt-get install -y apt-transport-https$ sudo apt-get update$ sudo apt-get install dotnet-sdk-2.2

5. Now that we have installed dotnet core SDK 2.2, we need to test if it’s successful by running this command on a new terminal

$ dotnet

If the command runs successfully, it will print out information about the dotnet core as seen below

Now that we have successfully installed dotnet core, Let’s start coding in dotnet core using VS Code. Make sure you have your terminal integrated into VS Code like mine

6. Create a Dotnet folder anywhere in your machine as seen below:

$ cd Documents$ mkdir CSHARP$ cd CSHARP

7. In your CSHARP folder, run the following command:

$ dotnet new console -o HelloWorld

The above dotnet command creates a new application of type console for you. The -o parameter creates a directory named HelloWorld

8. Open the folder HelloWorld in your VScode. Edit to the below:

Console.WriteLine(“Hello World! THis is my First Article \n Happy Coding”);

9. To see the output, run the following command:

$ Dotnet run

It will give you the below output

10. Congratulations!!!!!!!!!!!!!!!!!! You have completed level 0 of Dotnet core ninja for ubuntu. Happy coding

Photo by Kevin Ku on Unsplash

In the coming weeks, I will medium about setting your database, connecting to a database, CRUD Operations and many more.

--

--

Oluwasegun Haziz

AI Enthusiast, Software and Cloud Engineer. Passionate about highly scalable technology businesses, .NET, and FOH audio