January 26, 2022
How to install Mono software platform n Ubuntu 20.04

How To Install Mono On Ubuntu 20.04

On this article we will learn how to Install Mono, the open source project. Mono provides a .NET-compatible and C# compiler tool sets which make it possible to develop and run C# code in Linux.

Introduction

Mono is a software platform designed to allow developers to easily create cross platform applications part of the .NET Foundation. Mono is an open source implementation of Microsoft’s .NET Framework based on the ECMA standards for C# and the Common Language Runtime. On This tutorial, we will learn how to to install Mono on Ubuntu 20.04.

Mono Installation on Ubuntu 20.04

On this tutorial, we will use the last stable version of Mono repository for the installation process. Mono installation on Linux Ubuntu 20.04 will consist of several stages, but before we start we must pay attention to some prerequisites that must be met.

Prerequisite

Before we are starting to install Mono framework, there are will be prerequisites to be fulfill, as mention below :

  • Ubuntu 20.04 LTS System with sufficient disk space
  • root or non-root user with administrative privileges

Installing Mono On Ubuntu 20.04

As mentioned above, we will use Mono last stable version (6.12.0.122) for our source. The installation will be consist of several stage as mentioned below :

  • Adding Mono Repository
  • Installing Mono
  • Verifying Mono Installation
  • Testing Mono Framework

1. Adding Mono Repository

On this stage, we will add Mono repository to our Ubuntu system. here are the steps :

Update system and install dependencies packages, by submitting command line :

$ sudo apt update
$ sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common
mpik@worker1:~$ sudo apt update
[sudo] password for mpik: 
Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease                             
Hit:2 https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04  InRelease
Hit:3 http://us.archive.ubuntu.com/ubuntu focal InRelease
Hit:4 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:5 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done
Building dependency tree       
Reading state information... Done
mpik@worker1:~$ sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common
Reading package lists... Done
Building dependency tree       
Reading state information... Done
ca-certificates is already the newest version (20210119~20.04.2).
ca-certificates set to manually installed.
The following packages were automatically installed and are no longer required:
  chromium-bsu-data fonts-uralic libalut0 libglc0 libglewmx1.13 libopenal-data libopenal1 libsdl2-2.0-0
  libsdl2-image-2.0-0 libsndio7.0
 Install Mono on Ubuntu 20.04 | Update system and install dependencies packages
Install Mono on Ubuntu 20.04 | Update system and install dependencies packages

Import the repository’s GPG key, by submitting command line :

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
mpik@worker1:~$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
Executing: /tmp/apt-key-gpghome.OaW5D2dHt8/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
gpg: key A6A19B38D3D831EF: public key "Xamarin Public Jenkins (auto-signing) <releng@xamarin.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1
Install Mono on Ubuntu 20.04 | Adding GPG Key
Install Mono on Ubuntu 20.04 | Adding GPG Key

Add the Mono repository to your system sources’ list, by submitting command line :

$ sudo apt-add-repository 'deb https://download.mono-project.com/repo/ubuntu stable-focal main'
mpik@worker1:~$ sudo apt-add-repository 'deb https://download.mono-project.com/repo/ubuntu stable-focal main'
Get:1 https://download.mono-project.com/repo/ubuntu stable-focal InRelease [4,416 B]                          
Get:2 https://download.mono-project.com/repo/ubuntu stable-focal/main amd64 Packages [46.8 kB]                
Hit:3 http://us.archive.ubuntu.com/ubuntu focal InRelease                                                     
Hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease                                              
Hit:5 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease                                     
Hit:6 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease            
Hit:7 https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04  InRelease
Fetched 51.2 kB in 2s (27.5 kB/s)
Reading package lists... Done
Install Mono on Ubuntu 20.04 | Adding Mono Repository
Install Mono on Ubuntu 20.04 | Adding Mono Repository

2. Install Mono On Ubuntu 20.04

After all prerequisite package have been installed on the system, then we will install Mono application on Ubuntu 20.04. We will submit the command line :

$ sudo apt install mono-complete
Mpik@worker1:~$ sudo apt install mono-complete 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  chromium-bsu-data fonts-uralic libalut0 libglc0 libglewmx1.13 libopenal-data libopenal1 libsdl2-2.0-0
  libsdl2-image-2.0-0 libsndio7.0
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  binfmt-support binutils binutils-common binutils-x86-64-linux-gnu ca-certificates-mono cli-common

...

Setting up mono-complete (6.12.0.122-0xamarin1+ubuntu2004b1) ...
Setting up monodoc-http (4.2-3xamarin5+ubuntu2004b1) ...
Use of uninitialized value $libs in concatenation (.) or string at /usr/sbin/mono-xsp4-update line 216.
Processing triggers for systemd (245.4-4ubuntu3.11) ...
Install Mono
Install Mono

3. Verifying Mono Installation

After the installation was successfully done, then we will verifying it by querying Mono version. For this purpose, we will type the command line :

$ mono --version
mpik@worker1:~$ mono --version
Mono JIT compiler version 6.12.0.122 (tarball Mon Feb 22 17:33:28 UTC 2021)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	Interpreter:   yes
	LLVM:          yes(610)
	Suspend:       hybrid
	GC:            sgen (concurrent by default)
Mono Version

4. Testing The Mono

We just installed the Mono software platform successfully, on this stage we will try to use the Mono by creating a simple program which will print the legend ‘Hello World’ message in Bahasa Indonesia version ‘Halo Dunia!’.

Creating a simple file (with vi editor) and name it as ‘hello.cs’.

Paste the script :

using System;

public class HelloWorld
{
    public static void Main(string[] args)
    {
        Console.WriteLine ("Hallo Dunia !");
    }
}

Then build it with csc complier :

$ csc hello.cs
mpik@worker1:~$ csc hello.cs
Microsoft (R) Visual C# Compiler version 3.6.0-4.20224.5 (ec77c100)
Copyright (C) Microsoft Corporation. All rights reserved.

This step, will produce a new executable file called as ‘hello.exe’. We will call it by typing the command line :

$ mono hello.exe
mpik@worker1:~$ mono hello.exe
Hallo Dunia !

Then we will make this file to be run independently by changing its flag mode to be an executable.

$ chmod +x hello.exe

Then we just call this file only, and can be running smoothly.

mpik@worker1:~$ chmod +x hello.exe
mpik@worker1:~$ ./hello.exe
Hallo Dunia !
Mono | Hello World
Mono | Hello World

Conclusion

On this tutorial, we have learnt how to install Mono software platform on Linux Ubuntu 20.04 LTS operating system smoothly. I hope this article could be useful for any one.

Share this article via :

Leave a Reply

Your email address will not be published. Required fields are marked *