In this article, We are going to perform How to Install DotNet Core SDK on Ubuntu 18.04 LTS or any other cloud platform like Amazon EC2, Azure VM , Google compute cloud, etc., with preinstalled Ubuntu.
Table of Contents
Introduction
.NET Core is a free and open-source, software framework for Windows, Linux, and macOS operating systems. It is an open source, cross platform successor to .NET Framework.
Download and Install Microsoft keys for Ubuntu
First download and Install Microsoft keys for ubuntu 18.04 LTS using below command
$ sudo wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
Output:
Resolving packages.microsoft.com (packages.microsoft.com)... 13.84.47.71 Connecting to packages.microsoft.com (packages.microsoft.com)|13.84.47.71|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 3132 (3.1K) [application/octet-stream] Saving to: ‘packages-microsoft-prod.deb’ packages-microsoft-prod.deb 100%[================================================================================>] 3.06K --.-KB/s in 0s (524 MB/s) - ‘packages-microsoft-prod.deb’ saved [3132/3132]
Install Microsoft keys and feeds deb package.
$ sudo dpkg -i packages-microsoft-prod.deb
Install dependencies packages first
$ sudo add-apt-repository universe $ sudo apt-get update $ sudo apt-get install apt-transport-https $ sudo apt-get update
Install DotNet Core SDK on Ubuntu
Install dotnet core sdk 2.1 on ubuntu. To install specific version follow Microsoft official documentation.
$ sudo apt-get install dotnet-sdk-2.1
If you want to install dotnet core sdk 3.1 on ubuntu
$ sudo apt-get install dotnet-sdk-3.1
To verify if DotNet core in installed
$ dotnet
Output:
Usage: dotnet [options] Usage: dotnet [path-to-application] Options: -h|--help Display help. --info Display .NET Core information. --list-sdks Display the installed SDKs. --list-runtimes Display the installed runtimes. path-to-application: The path to an application .dll file to execute.
To check dotnet core version
$ dotnet --version
Output:
dotnet --version 2.1.805
Creating .NET core Project
Lets create directory named testproject
$ sudo mkdir testproject
Navigate to testproject directory
$ cd testproject/
Lets create new dot net project named fosstechnix
$ sudo dotnet new console -o fosstechnix
Output:
The template "Console Application" was created successfully. Processing post-creation actions... Running 'dotnet restore' on fosstechnix/fosstechnix.csproj... Restore completed in 161.24 ms for /home/user/testproject/fosstechnix/fosstechnix.csproj. Restore succeeded.
Now, navigate to the project directory with the following command:
$ cd fosstechnix/
Check the project files
$ ls
Output:
ls fosstechnix.csproj obj Program.cs
To check main program file
$ cat Program.cs
Output:
cat Program.cs using System; namespace fosstechnix { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } }
Running .NET core project
Use below command to run dotnet project
$ sudo dotnet run
Output:
sudo dotnet run Hello World!
Conclusion
We have covered How to Install DotNet Core SDK on Ubuntu 18.04 LTS
Related Articles