How to install DotNet Core on Ubuntu 18.04

Install the DotNet Core on Ubuntu 18.04, so you can build your apps on the open source platform.

How to install DotNet Core on Ubuntu 18.04

If you or your company depend upon Microsoft's DotNet for the development of certain projects on your data center servers, you may assume yourself out of luck on the Linux platform. That assumption would be incorrect, as Microsoft has not only made it possible to install the DotNet Core on Linux, they've made it quite simple.

With DotNet installed on your favorite open source platform, you can develop to your heart's content and your skill limits.

SEE: Hiring kit: Database administrator (TechRepublic Premium)

I want to walk you through the process of installing DotNet Core on Ubuntu Server 18.04 and then how to create your first Hello World app. I'll assume you already have the Ubuntu platform up and running and a user account with sudo privileges.

With that said, let's get to work.


The first thing to do is install the necessary repository. To do this, open a terminal window and issue the following commands:

wget -q
sudo dpkg -i packages-microsoft-prod.deb

Once the repository has been added, there's a single dependency that must be installed. Do this with the following commands:

sudo add-apt-repository universe
sudo apt-get install apt-transport-https

Finally, install DotNet Core with these commands:

sudo apt-get update
sudo apt-get install dotnet-sdk-2.2

After running the last command, it will take some time to populate the local package cache. This is done to enable offline access, and shouldn't take more than a minute or so to complete this process. Once it completes, you should have your bash prompt returned. Log out and log back in, and you're ready to go.

After you've logged back in, issue the command dotnet to verify everything has installed (Figure A).


Figure A: DotNet Core is installed.

Hello World

Let's create the always popular Hello World example. To do this, you need to create a new console app with the command:

dotnet new console -o HelloWorld

The above command informs DotNet that you are creating a new console app named HelloWorld. The command will also instruct DotNet to populate the app with the required files. Once it completes, change into the newly created directory with the command:

cd HelloWorld

Within that directory, you'll find a file named Program.cs. That file contains all the necessary code to print "Hello World!" to the console (Figure B).


Figure B: Hello World!

You can run the Hello World app with the command:

dotnet run

The command will then print out Hello World! (Figure C).


Figure C: A successful command run.

You can modify that Program.cs file in any way you need, but at this point you should have everything necessary to start building your DotNet apps on the Linux platform.

Also see