In this article, we will discuss how we can setup .NET Core on Linux environment, a prerequisite for developing a console application on Linux. We discussed understanding about .NET Core with "Hello World" application on Windows in my previous article, at the following link.
Let’s start with the prerequisites
You have to download the following software and install them on your PC
- VMware
- Ubuntu 14.4 / Linux Mint 17
- .NET Core SDK 1.0
VMware
Option I - You can download the trial version and install VMware from the
VMware site
Option II - You can download open source and install Virtual Box from the
Virtual Box Community site
Ubuntu 14.04
You can download and install the Ubuntu OS from the
Ubuntu site.
.NET Core SDK
You can download and install the .NET Core SDK as following commands.
sudo apt-get install dotnet-dev-1.0.0-preview2-003131
Let’s start implementation
You are able to implement .NET Core with different methods such as Command line and Visual Studio Code Editor.
Setting up the Environment
Using Command line, procedures are given below,
If you want to know how to install the .NET Core on Ubuntu 14.4 / Linux Mint 17, let’s start with step-by-step guidelines,
- Open the Terminal Emulator
- Copy and past the following command in Terminal, then Enter
sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
- Copy and paste the following command in Terminal, then Enter
sudo apt-get update
- Copy and paste the following command in Terminal, then Enter
sudo apt-get install dotnet-dev-1.0.0-preview2-003131
Developing a Hello World Console Application on Linux
- Type mkdir Project cd Project and Enter in the command line.
- Type mkdir ConsoleHelloWorldApp, cd ConsoleHelloWorldApp and Enter in the command line.
- Type dotnet new and Enter in the command line, given below
- Type dotnet restore and enter in the command line, given below
- Type dotnet run and enter in the command line, given below
Program.cs
- using System;
-
- namespace ConsoleApplication
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- Console.WriteLine("Hello World!");
- }
- }
- }
Developing a Display Current DateTime Console Application on Linux
- Open program.cs with gedit
- You can implement the get current date time functional and call the function in main method
- Type dotnet run and enter in the command line, given below
Program.cs
- using System;
-
- namespace ConsoleApplication
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- GetDateTime();
- }
-
- public static void GetDateTime()
- {
- DateTime date=DateTime.Now;
- Console.WriteLine("Date Time on today: "+ date);
- }
- }
- }
You can also read this article in my blog here
Reference
Conclusion
I hope you understood how to setup .NET Core on a Linux environment and how to run it. I have covered all the required steps. If you find anything that I missed in this article, please let me know. Please share your valuable feedback or suggestions.