Mono platform is used to develop and run cross-platform applications. It is open-source and free implementation by the Microsoft. This tutorial explains how to install Mono on Debian 10.
Prerequisites
Before you start installation, make sure you have logged in as root or user with sudo privileges.
Installing Mono on Debian
Standard Debian repositories does not includes Mono package. We will install the Mono package from the official Mono’s repositories. It is a very easy to install. Perform the following steps:
1. Start by installing the necessary packages:
sudo apt update
sudo apt install dirmngr gnupg apt-transport-https ca-certificates
2. Import the repository’s GPG keys using below command:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
The output should look like below:
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 system sources list:
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. Update the packages list and install Mono, after the apt repository is enabled:
sudo apt update
sudo apt install mono-complete
The mono-complete
is a meta-package and it will install other required packages for Mono development, including the runtime, development tools, and all libraries.
5. Verify the installation printing the Mono version:
mono --version
At the time of writing this article, the latest stable version of Mono is 6.8.0 Stable (6.8.0.123).
Mono JIT compiler version 6.8.0.123 (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 it. Mono installed successfully on your Debian system, you can start developing your application.
Mono Program Example
We will create a simple Hello World program to check that everything is set up perfectly.
Open your text editor and create a file named hello.cs
with the following content:
using System;
public class HelloWorld
{
public static void Main(string[] args)
{
Console.WriteLine ("Hello World!");
}
}
To build the program use the csc
compiler:
csc hello.cs
It will create a executable with name hello.exe
Run the executable using the command below:
mono hello.exe
The output should show something like this:
Hello, World
Make the file executable to execute the program only by typing its name:
chmod +x hello.exe
You can now run the hello.exe
file by typing:
./hello.exe
Conclusion
You have learned successfully how to install latest stable Mono on Debian from the official Mono repositories.
If you have any question or feedback, please leave a comment below.