How to Install Mono on Ubuntu 22.04

Mono is open-source and available for everyone without any charges. It is Microsoft’s .NET Framework supported which is supported by C#, C, Python, and PHP. Mono encourages Windows developers to bridge-building between Windows and Linux.

This educational material aims to provide procedural steps to install Mono on Ubuntu 22.04.

How to Install Mono on Ubuntu 22.04

Mono is an open-source implementation of Microsoft’s .NET Framework supported by C#, C, Python, and PHP. The following steps explain the complete process of installing Mono on Ubuntu 22.04.

Step 1: Adding GPG key for Data Encryption

Add the GPG key to ensure that the repository is being added from an authentic source:

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

Step 2: Adding Mono Repository to Ubuntu Local Repository

Top 10 Linux Distros

Add a Mono repository to your Ubuntu 22.04 repository and list it with the following command:

$ echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list

The command has been executed successfully without any error.

Step 3: Update System Cache

To update the system cache with the update command as follows

$ sudo apt update

Step 4: Install Mono-devel (Developer) Package

Install the Mono-devel package by using the command mentioned below:

$ sudo apt install mono-devel

As per the output, Mono and all its relevant packages are installed successfully.

How to use Mono on Ubuntu 22.04

Now it’s time to practically implement the functionality of Mono on Ubuntu 22.04. This section provides a list of sequential steps to use Mono on Ubuntu 22.04.

Step 1: Create a New File with *.cs Extension

Create and open a new file with a .cs extension by issuing the following command:

$ nano foss.cs

The foss.cs will open up in a nano editor as shown below. Write your programming script and press CTRL+O to overwrite the file.

Step 2: Compile the .cs File via Terminal

The csc is a c sharp compiler used for running the script file from the terminal. The csc compiler will create an exe from the foss.cs file:

$ csc foss.cs

The command will create a “.exe” file of the “foss.cs”.

Step 3: Run the .exe with Mono

In the last step, you will see how to execute the file with Mono. Execute the “foss.exe” file from the terminal as follows:

$ mono foss.exe

You can see that the C sharp script is executed successfully and returns the same message you have written in the nano editor.

How to remove mono from Ubuntu 22.04

Mono was installed using the apt package manager on Ubuntu 22.04. To remove Mono from Ubuntu 22.04, we have practiced the following command:

$ sudo apt autoremove mono-runtime --purge 

The command will remove all the packages files and dependencies of Mono from Ubuntu 22.04.

Now, you are able to install and use Mono on Ubuntu 22.04.

Conclusion

Mono, Microsoft’s .NET Framework, can be installed on Ubuntu 22.04 by adding its repository to Ubuntu’s repository. Mono is an open-source as well as a cross-platform utility that is based on the Microsoft .NET framework. With Mono, you can run and compile your script in the terminal window. Following the steps carefully, will lead you to implement the commands to install and use Mono on Ubuntu 22.04.