Install Mono on Ubuntu 20.04

Install Mono on Ubuntu 20.04

Mono is a cross-platform implementation of Microsoft's .NET framework for developing applications using C# or other CLR language. Mono is an open-source project based on the ECMA standards.

This tutorial explains how to install Mono on Ubuntu 20.04.

Install Mono

Retrieve public key from a keyserver and add it to the list of trusted keys.

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key D3D831EF

Add the Mono repository:

echo "deb http://download.mono-project.com/repo/ubuntu stable-$(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list

Update the package lists:

sudo apt update

Install Mono:

sudo apt install -y mono-complete

The mono-complete is a package that includes the Mono runtime, development tools and all libraries.

When installation is finished, we can check Mono version:

mono --version

Testing Mono

Create a Test.cs file:

nano Test.cs

Add the following code:

using System;

public class Test
{
    public static void Main()
    {
        Console.WriteLine("Hello world");
    }
}

Build program using the csc compiler:

csc -out:test.exe Test.cs

This command will build an executable file named test.exe. Add the execute permission:

chmod a+x test.exe

Run a program:

./test.exe

Uninstall Mono

If you want to completely remove Mono, run the following command:

sudo apt purge --autoremove -y mono-complete

You can also remove dependencies that has been installed during the Mono installation:

sudo apt purge --autoremove -y binfmt-support binutils lynx

Remove GPG key and repository:

sudo apt-key del D3D831EF
sudo rm -rf /etc/apt/sources.list.d/mono-official-stable.list

You can also remove Mono related directories:

sudo rm -rf /etc/mono
sudo rm -rf /usr/lib/mono

Leave a Comment

Cancel reply

Your email address will not be published.