How to install Mono on Ubuntu 20.04

s2 0

Mono is a platform for developing and operating cross-platform applications based on the ECMA / ISO standards. It is a free, open source implementation of Microsoft’s .NET framework.

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

requirements

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

Install Mono on Ubuntu

Mono is not available in the standard Ubuntu 20.04 repositories. We install the mono packages from the official mono repositories:

  1. Install the dependencies required to add a new repository over HTTPS:

    sudo apt updatesudo 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 should look something like this:

    gpg: key A6A19B38D3D831EF: public key "Xamarin Public Jenkins (auto-signing) <[email protected]>" imported
    gpg: Total number processed: 1
    gpg:               imported: 1
  3. Add the Mono repository to your list of system sources:

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

    sudo apt install mono-complete 

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

  5. The installation can take a few minutes. When you’re done, check it out by typing the following command which will print the mono version:

    mono --version

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

    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 it, Mono has been installed on your Ubuntu machine and you’re ready to use it.

Getting started with mono

To ensure that everything is set up correctly, we are building a Hello World program that outputs 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 create the program:

csc hello.cs

The above command creates an executable named hello.exe.

Run the executable:

mono hello.exe

The output should look something like this:

Hello, World

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

chmod +x hello.exe

You can now do the hello.exe File by entering:

./hello.exe

diploma

Installing Mono on Ubuntu 20.04 is a relatively simple process and only takes a few minutes.

If you run into any problem or have any feedback, please leave a comment below.