Qadry
unixcop Admin

How to install and use Mono on Ubuntu

Introduction

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.

Installing Mono on Ubuntu 21.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:

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

In addition to, install the apt dependencies for mono by using the command:

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

2: Importing GPC Key

So 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 above.

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'

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.

$ sudo apt install mono-complete

So The Mono runtime along with relevant tools and libraries will be installed successfully.

Verifying the Mono installation

Type the following command in the terminal window to verify mono was installed:

$ mono --version

In addition to The installed Mono version displayed in the output.The latest version of Mono available at the time of download was 6.8.0.122. This version might vary at the time of your download.

Create a program in Mono

I’ll show you how to create a small C# ‘We love unixcop’ program to test our Mono installation.Let’s create a .cs file and then save it under the name unixcop.cs

1. Save your C# code in a file called unixcop.cs

code is:

using System;

namespace Project_1 {
    class MainClass {
        public static void Main (string[] args) {
            Console.WriteLine ("We love Unixcop!");
            Console.ReadKey ();
        }
    }
}

2. Make unixcop.cs executable. Right-click the unixcop.cs file -> select Properties -> Permissions tab -> put a check mark to the left of Allow executing file as program as shown.

3. Change directories using the cd command to the directory that contains the unixcop.cs file.

4. Use the mcs compiler and create a Windows executable named unixcop.exe from the source unixcop.cs.

$ mcs -out:unixcop.exe unixcop.cs

5. Run the unixcop.exe program with mono.

$ mono unixcop.exe

Conclusion

In this article, we saw how to install Mono on an Ubuntu 21.04 system in detail. We then verified the installation of the application and wrote a small unixcop script to test the Mono C# compiler.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

x