DEV Community

dwarfŧ
dwarfŧ

Posted on

getting started with c# on linux

step 1
i am using ubuntu, which is a debian based linux distro. I installed it with:

wget -nv https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get install apt-transport-https
sudo apt install snapd
sudo service snapd start
sudo snap install dotnet-sdk --classic
sudo apt-get install mono-complete

Enter fullscreen mode Exit fullscreen mode

WARNING: this will only work with debian, please find how to install c# on your linux distro.

step 2
next we can create a main.cs file. The .cs extension is c# files. here is a hello world program:

using System;

public class main {
  public static void Main(String[] args){
    Console.WriteLine("Hello, World!");
  }
}
Enter fullscreen mode Exit fullscreen mode

this will log "Hello, World!" into the terminal.

step 3
compiling on linux is a bit different. In step 1 we install c#. This allows us to compile c# code. to compile we can do: mcs main.cs this will give us a main.exe file. Don't worry! This isn't a windows exe file because then we wouldn't be able to execute it. No, this is just a standard machine code file which we can execute by doing: ./main.exe And done! It will output or hello world program!

step 4
enjoy and keep on coding.

Top comments (0)