How to Install Mono Framework on Debian 11 Bullseye

Mono is a free, open-source development platform based on the .NET Framework. Mono’s .NET implementation is based on the ECMA/ISO standards for C# and the Common Language Infrastructure. The Mono project has been in development for over a decade and continues to feature in many applications.

In the following tutorial, you will know how to install and configure Mono on your Debian 11 Bullseye operating system.

Prerequisites

  • Recommended OS: Debian 11 Bullseye
  • User account: A user account with sudo privilages or root access (su command).
  • Required Packages: ssee install required dependencies

Updating Operating System

Update your Debian 11 operating system to make sure all existing packages are up to date:

sudo apt update && sudo apt upgrade

Root or Sudo Access

By default, when you create your account at startup with Debian compared to other distributions, it does not automatically receive sudoers status. You must either have access to the root password to use the su command or visit our tutorial on How to Add a User to Sudoers on Debian.

Install Required Dependencies

The following dependencies will be required to successfully install and run Mono on your Debian 11 Bullseye system. Open your command terminal and run the following command to install and check if they are installed.

sudo apt install dirmngr gnupg apt-transport-https ca-certificates -y

Import Mono GPP Key & Repository

The first part of the installation will be to import the GPG key and repository as Debian 11 does not come with Mono in its repository.

First, import the GPG key:

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

Next, import the Mono repository:

sudo sh -c 'echo "deb https://download.mono-project.com/repo/debian stable-buster main" > /etc/apt/sources.list.d/mono-official-stable.list'

Note, this is the Buster repository. However, it works for Bullseye.

Now with the GPG key and Mono repository added, update your repository list to reflect the changes.

sudo apt update

Install Mono Framework

Now that you have the repository successfully installed, it is time to install Mono itself. To do this, you will use the following apt install command.

sudo apt install mono-complete -y

Next, verify the installation and the version installed.

mono --version

Example output:

Mono JIT compiler version 6.8.0.105 (Debian 6.8.0.105+dfsg-3.2 Tue Jun 29 21:01:01 UTC 2021)

An alternative to verify the installation of the Mono Framework is to use the apt-cache policy command.

sudo apt-cache policy mono-complete

Example output:

mono-complete:
  Installed: 6.8.0.105+dfsg-3.2
  Candidate: 6.8.0.105+dfsg-3.2
  Version table:
 *** 6.8.0.105+dfsg-3.2 500
        500 http://ftp.au.debian.org/debian bullseye/main amd64 Packages
        100 /var/lib/dpkg/status

Create a Test Application

To check that Mono is working, you will create a small program with the famous catchphrase (Hello World). You will do this by opening your favorite text editor to accomplish this. For the guide, we will use the nano text editor.

Open your terminal, and create a .cs file as below.

sudo nano helloworld.cs

Next, enter the following programming code:

using System;

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

Once done, CTRL+O to save, then  CTRL+X to exit.

Now you can compile the code. To do this, execute the following command:

mono-csc helloworld.cs

The compiler command will build an executable named helloworld.exe, once complete you can run this to see the code in action by executing the following command:

mono helloworld.exe

You will then get the classic output:

Hello World!

An alternative way to execute the program is by making the file executable by itself. This can be done by changing the permissions of the file as below:

chmod +x helloworld.exe

Now you can run the file on its own by executing the following command:

./helloworld.exe

You should receive the Hello World output again. If you have trouble at any time, you may need to set the $PATH variable.

export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"

Comments and Conclusion

In the guide, you have learned to install the Mono framework and execute your first small program on your Debian 11 Bullseye system. Overall, Mono is a terrific option for developers that is cross-platform with not having to pay for software licenses or vendor lock-ins along with being open-source. The only downside to Mono is that sometimes its API cannot be as up to date immediately when a new version of the .NET framework is released.

For more information on using Mono, visit the official documentation



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!