How to install DotNet Core on Ubuntu 18.04
By Flenn Ruiz
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.
Data Center Must-Reads
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 https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.debsudo 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 universesudo apt-get install apt-transport-https
Finally, install DotNet Core with these commands:
sudo apt-get updatesudo 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).
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:
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).
You can run the Hello World app with the command:
The command will then print out Hello World! (Figure C).
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.
- How to know who logged into your data center Linux servers (TechRepublic)
- How to find and kill zombie processes on your Linux data center servers (TechRepublic)
- How to change the default SSH port on your data center Linux servers (TechRepublic)
- How to install Microsoft Visual Studio Code (VS Code) on Ubuntu (TechRepublic)
- Machine learning for .NET devs: ML.NET goes GA (ZDNet)
- Hyperconverged infrastructure: A cheat sheet (TechRepublic)
- 10 things companies are keeping in their own data centers (TechRepublic download)
- How hyperscale data centers are reshaping all of IT (ZDNet)
- Best cloud services for small businesses (CNET)
- DevOps: More must-read coverage (TechRepublic on Flipboard)