Linux

How to Install Mono on Ubuntu 20.04

How to Install Mono on Ubuntu 20.04

Mono is a platform for developing and running cross platform applications based on ECMA / ISO Standards. This is a free and open-source implementation of the Microsoft .NET framework.

This tutorial covers the steps needed to install Mono on Ubuntu 20.04.

Precondition

The instructions assume that you are logged in as root or as a user with sudo privileges.

Install Mono on Ubuntu

Mono is not available in the standard Ubuntu 20.04 repository. We will install the Mono package from the official Mono repository:

  1. Install the dependencies needed to add a new repository via HTTPS:

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

2. Import the repository’s GPG key:

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

The output will look like this:

Output :

gpg: key A6A19B38D3D831EF: public key "Xamarin Public Jenkins (auto-signing) <releng@xamarin.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1

3. Add a Mono repository to your system’s source list:

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

4. Install Mono:

sudo apt install mono-complete 

mono-complete is a meta package that installs Mono runtime, development tools, and all libraries.

The installation may take several minutes to complete. When finished, verify by typing the following command which will print the Mono version:

mono --version

At the time of writing this article, the latest stable version of Mono is 6.8.0.123.

Output :

Mono JIT compiler version 6.8.0.123 (tarball Tue May 12 15:11:57 UTC 2020)
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)

That’s all, Mono has been installed on your Ubuntu machine, and you can start using it.

Get started with Mono

To make sure everything is set up correctly, we will build a Hello World program that prints the classic “hello world” message.

Open your text editor and create a file called hello.cs with the following content:

hello.cs
using System;

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

Use the csc compiler to build the program:

csc hello.cs

The above command will create an executable named hello.exe.

Run the executable:

mono hello.exe

The output will look like this:

Output :

Hello, World

To run a program just by typing its name, set an executable flag:

chmod +x hello.exe

You can now run the hello.exe file by typing:

./hello.exe

Conclusion

Installing Mono on Ubuntu 20.04 is a relatively easy process, and you only need a few minutes.

If you experience problems or get feedback, leave a comment below.

Related posts

How to Install the NoSQL Apache CouchDB Database on CentOS 8

Linux

How Linux makes data recovery easy

Linux

How to use GNU Debugger on Linux

Linux

How to Add SWAP Space on Ubuntu 20.04

Linux

How to properly secure sysctl on Linux

Linux

How to Install Nextcloud with Nginx and Let’s Encrypt SSL on Ubuntu 20.04 LTS

Linux

How to use the chmod command on Linux

Howto

How to Install Nginx with PHP and MySQL (LEMP Stack) on Ubuntu 20.04 LTS

Linux

Linux Pinky Command Tutorial for Beginners (8 Examples)

Linux