Run C# code on linux terminal

Of course it can be done and the process is extremely simple.

Here I am explaining the steps for Ubuntu Linux.

Open terminal:

Ctrl + Alt + T

Type

gedit hello.cs

In the gedit window that opens paste the following example code:

using System;
class HelloWorld {
  static void Main() {
    Console.WriteLine("Hello World!");
  }
}

Save and close gedit.

Back in terminal type:

sudo apt update
sudo apt install mono-complete
mcs -out:hello.exe hello.cs
mono hello.exe

Output:

Hello World!

Leave a Comment