How To Install Mono On Ubuntu

Mono, an open-source .NET framework, can primarily be used on Ubuntu or other Linux distributions to run legacy .NET Framework applications or to develop cross-platform games with Unity or mobile apps with Xamarin. Furthermore, it supports languages like C#, F#, Java, and Python. This guide will explain the installation of Mono on Ubuntu and also demonstrate a simple program execution.

Mono Package Installation on Ubuntu?

To install Mono on Ubuntu there are two ways, one is by using its repository and the other is by building it from its source file. However, using the tar file for Mono installation can be tiresome, so here I have used the repository method. Before directly jumping to adding the repository first, install GNU Privacy Guard to verify the authenticity of packages and repositories:

sudo apt install ca-certificates gnupg

 

Installing GNU Privacy Guard on Ubuntu for validation of repositories

Next, add the GPG key for the Mono framework using the below command:

sudo gpg --homedir /tmp --no-default-keyring --keyring /usr/share/keyrings/mono-official-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

Adding GPG key for Mono repository on Ubuntu

Now add the repository for the stable version of Mono to the apt packages list

echo "deb [signed-by=/usr/share/keyrings/mono-official-archive-keyring.gpg] https://download.mono-project.com/repo/ubuntu stable-focal main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list

Adding Mono repository on Ubuntu

Further, refresh the apt packages list:

sudo apt update

Updating the apt packages list on Ubuntu

Now install Mono on Ubuntu by executing the below command:

sudo apt install mono-complete -y

Verify, the installation for mono by listing its version using:

mono --version

Checking mono version on Ubuntu

Testing Mono on Ubuntu

For beginners, I have posted a simple code that displays the given info to demonstrate how a program can be executed using Mono:

using System;
public class monotest
{
public static void Main(string[] args)
{
Console.WriteLine ("Hello and welcome to Itslinuxguide.com");
}
}

Create a .cs file using the nano editor and then paste the above code, after save and close the file:

a simple code that displays the given info to demonstrate how a program can be executed using Mono

Now use the csc compiler to create an executable file from the source file;

csc test-code-mono.cs

Creating an executable file for running a program using mono on Ubuntu

Next, run the executable file to see the code output:

mono test-code-mono.exe

 

Running a simple using mono on Ubuntu

Note: There is an Integrated Development Environment for Mono named MonoDevelop or Xamarin Studio which is discontinued but still can be used for writing, debugging, and managing Mono apps. Moreover, it has a code editor, project builder, and GUI designer.

Conclusion

To install Mono on Ubuntu, add its GPG key and the respective repository. Afterward, use the apt app installer. Mono is a free and community-driven framework that can be used to write GUI-based desktop apps using Windows Forms or GTK and to develop dynamic websites using Mono’s implementation of ASP.NET.

 

Index
Scroll to Top