Mono is the OpenSource implementation of the Microsoft .NET software stack. It is based on ECMA/ISO standards and implements the C# programming language and the Common Language Runtime. To find out more about Mono, have a look at the Mono project website.
In this article, I will show you how to install the Mono Stack and c# language runtime on Ubuntu Linux. We will be using Ubuntu 20.04 system here.
A user account with sudo privileges.
Installing Mono on Ubuntu 20.04
By default, the Mono application is not found in the Ubuntu systems. To install Mono from the official repository follow the steps given below:
Step 1: Installing the dependencies
Let’s start off by adding new repositories over HTTPS. To do so, first update the apt repository using:
$ sudo apt update
Now install the apt dependencies for mono by using the command:
$ sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common
The system might prompt to ask the user for their confirmation. Press Y and then hit enter key from the keyboard to proceed.
Step 2: Importing GPC Key
After adding the repository users are required to extract the key and place it on the Ubuntu server.
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
This way users can easily import the GPC key. The output will look like the one displayed below:
Step 3: Adding Mono repository
Now, to add the mono repository to the source’s list of the system, append the following command in the terminal window:
$ sudo apt-add-repository 'deb https://download.mono-project.com/repo/ubuntu stable-focal main'
Step 4: Installing Mono
Once you have installed all dependencies of Mono, the next step is to install Mono. We will be installing mono-complete package.
The complete package will begin to install when you type Y and hit the enter key from your keyboard at the prompt of the system.
The Mono runtime along with relevant tools and libraries will be installed successfully.
Verifying the Mono installation
To verify the installation process, type the following command in the terminal window:
$ mono --version
You will see that the installed Mono version displayed in the output. The latest version of Mono available at the time of download was 184.108.40.206. This version might vary at the time of your download.
Create a program in Mono
In this chapter. I’ll show you how to create a small C# ‘hello World’ program to test our Mono installation. Let’s create a .cs file and then save it under the name test.cs
We will be using the csc compiler to build this program.
$ csc test.cs
This command will then create a hello.exe file. Now, run this file using:
$ mono test.exe
The output will display Hello, World.
In this article, we saw how to install Mono on an Ubuntu 20.04 system in detail. We then verified the installation of the application and wrote a small Hello-World script to test the Mono C# compiler.