There is a new version of this tutorial available for Ubuntu 22.04 (Jammy Jellyfish).

how to install Mono on Ubuntu 20.04

This tutorial exists for these OS versions

On this page

  1. Conclusion

Mono is free, open-source software based on ECMA standards of the .net framework. It enables developers to establish cross-platform applications which belong to the .NET foundation. Mono is unnecessary if we are working on Linux, but if you have any other platform as a target, then it is always required. I.e., android, windows, etc. Microsoft has sponsored this reliable project to support operating systems of 32 and 64-bit architecture. Mono originated from Xamarin, a free extension and subsidiary of Microsoft. Mono is written in C, C#, and XML languages. We can run binaries produced by .net compilers from Microsoft as Mono has binary compatibility with Windows. Mono has remoting infrastructure that enhances the performance and working of the ASP.net engine. Strong error handling capability is also a feature of Mono’s C# compiler. Such specifications help users to work effectively by installing mono. We have created this article guide to help you understand the functionality of Mono in Ubuntu 20.04.

The following topics are included in the ongoing article

  • Installation process
  • Getting started with Mono with an example

Prerequisites

As an initial step, you must first have a box to install Ubuntu. While configuring the Virtual box, you need to import the Ubuntu file from your computer. After successful installation and configuration, you will now have the privilege of accessing Ubuntu. While establishing Ubuntu, you provided a username and password. Ubuntu will acquire this information from the user at each start for verification. To run commands in the terminal portal, you must log in as a root.

                         

Installation process

On entering the Ubuntu interface after providing a username and password. Go to all applications and select terminal. When you open the terminal, you will see the username as a root at the start of the terminal. In Ubuntu systems, mono applications are not found. They are installed from the official repository. The installation process consists of the following steps

  • Update Package
  • Install dependencies
  • Extract the GPC key
  • Add mono directory in the server
  • Mono installation
  • Verification

Step 1: Update Package

While writing the command, the system will ask about the password for the confirmation and then move forward. It might take a few minutes to update. Then, in the end, you will view the “reading package lists….Done” which implies the list of packages is updated.

$ sudo apt update

Step 2: Install dependencies

The essential apt dependencies are installed by typing the following command.

$ sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common

This query will take a bit longer than other queries. Installing dependencies of any software is very important because, by default, no mono application doesn’t exist. So, we first install dependencies to get mono from the official repository.

Step 3: Extract GPC key

After adding the repository, the user will be prompted to install the upgraded mono versions in the Ubuntu server. The following method is implemented to import the GPC key. As a number of keys are present against each version of mono.

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

Step 4: Add a mono directory in the server

This query adds the extracted key from the above command to the server.

$ sudo apt-add-repository 'deb https://download.mono-project.com/repo/ubuntu stable-bionic main

Step 5: Mono Installation

Before installing mono, updating the packages is required to ensure the existence of APT in the Ubuntu server.

$ sudo apt update

Mono installation takes more time as compared to any other software on Ubuntu .i.e. Yarn.

$ sudo apt install mono-complete

To install a complete mono setup, the System first asks for the password we have initiated for the user after this process is continued.

Step 6: Verification

We can test the installed application. This test is optional. This is used to test the nth number of unit tests.

$ sudo apt install monodevelop-nunit

After the installation of mono software, it’s time to verify the operation performed.

$ Mono –version

This command will bring the following output. This corresponding output implies the compiler version of mono. This is the latest version, which is downloaded at installation time. It’s the launching date. “Xamarin” is a subsidiary of Microsoft. The command cited below shows the output, which consists of a description of the operation. There is no disability shown.

Getting started with Mono with examples

Here, we will quote a simple example to understand how it’s working. We will create a program on a text file and bring its output from the terminal through commands. There is no specific rule for creating a mandatory text file. You can add any text in the text editor. But making the file with the “.cs” extension is important.

Step 1: Go to all applications, search your text editor, and select it to open.

Step 2: Write the following code in the file after opening the text editor. Here we have created a class “Aqsa”. In the main function, a string argument is passed. To print, we will use the command "Console.writeline". The specific output we want is the string “ I am Aqsa”.

Step 3:  Now save that particular file and close it. The file is saved with the extension of .cs.

Step 4: Go back to the terminal to enter commands.

Csc is a compiler. It is used to build a program.

$ csc file.cs

After a successful compilation of the above command, a .exe file will be created in the local directory with the name, which is mentioned in the script. For instance, file.exe is created.

$ mono file.exe

This command will execute file.exe. The output of the query will be :

Conclusion

We saw how to install and configure Mono on Ubuntu 20.04. Each query is explained step by step in proceeding towards completion of installation. Following this article, it will be remarkably easy for the user to conduct all commands till the verification of the software. To test the mono C# compiler, a message is displayed by introducing a “.cs” file.

Share this page:

0 Comment(s)