How to install Mono on Debian 10

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

This article contains information on how to install Mono on Debian 10.

Prerequisites

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

Installing Mono on Debian

Mono is not available in the standard Debian repositories. We will install Mono packages from the official Mono repositories. This is a relatively simple process that only takes a few minutes.

  1. Start by installing the required packages:
    sudo apt update
    sudo apt install dirmngr gnupg apt-transport-https ca-certificates
  2. Enter the following command to import the repository GPG key:
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

    The output should look 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 the list of system sources:
    sudo sh -c 'echo "deb https://download.mono-project.com/repo/debian stable-buster main" > /etc/apt/sources.list.d/mono-official-stable.list'
  4. After enabling the apt repository, update the package list and install Mono:
    sudo apt update
    sudo apt install mono-complete

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

  5. Verify the installation is correct by printing the Mono version:
    mono --version

    At the time of this writing, the latest stable version of Mono is 6.8.0 Stable (6.8.0.105).

    Mono JIT compiler version 6.8.0.105 (tarball Tue Feb  4 21:20:43 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. You have successfully installed Mono on Ubuntu and you can start developing your application.

Getting started with Mono

To make sure everything is configured correctly, we will create 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 command above will create an executable file named hello.exe.

Run the executable with the command below:

mono hello.exe

The output should look something like this:

Hello, World

To be able to execute a program just by entering its name, you need to make the file executable:

chmod +x hello.exe

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

./hello.exe

Output

The latest stable releases of Mono are available for installation from the official Mono repository.

If you run into an issue or have feedback, please leave a comment below.

Sidebar