Once the update process completes, run the command below to install the required dependencies. Some packages are required to install Mono because they are the tools that Mono uses. There are several ways in which you can install these packages. Use a package manager. This is the easiest way to install required dependencies, as they will be compatible with your distribution’s package manager and can be installed automatically.
sudo apt install software-properties-common dirmngr gnupg apt-transport-https ca-certificates -y
Now that you have the required packages, follow the steps below to install Mono Framework on your Debian Linux machine.
The base Debian 10 repositories do not include any Mono package by default, so to install Mono, you need to add a third-party repository first. This example uses the Mono repository from its developer.
1. Run the sudo apt-key adv command below to add the GPG repository key to your APT. The package manager uses a repository key to authenticate the packages you intend to install. It ensures that you receive a package from a trusted source and prevents any malicious packages from being installed on the Debian 10 machine.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
2. Once you’ve run the above command and successfully added the GPG key, run the command below to add the necessary package repository for installing Mono on Debian 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'
3. After adding the Mono repository, run the apt update command to refresh the package list with the new repository information and get the latest packages available.
sudo apt update -y
4. Next, run the sudo apt-policy mono-runtime command to check if Mono is available in your repository. The output below has no missing packages. But you should review the result of this command carefully and install any missing packages listed there.
sudo apt-policy mono-runtime
Sample output:
5. At this point, you are ready to install Mono. Run the apt install below command to get started.
sudo apt install mono-complete -y
The package manager will now download and install Mono Framework on your Debian machine, and a new binary called mono will also be installed. mono-complete is a meta package that is a complete set of tools. When you run the command sudo apt install mono-complete , it will install several packages, including:
6. Once the installation has finished, run the command mono –help to check out the Mono Help menu.
mono --help
7. You can check out the Mono version that you have installed by running the following command.
mono --version
Now that you have the Mono framework installed on your Debian Linux machine, you can create a very simple hello world C# application.
A hello world C# application is a simple program designed to introduce you to C# programming, and more specifically, the features required for compiling a program. It’s often your first exposure when learning a new language or framework.
1. Run the following command to create a new directory named hello-world, in which we will place our hello world c# application.
mkdir hello-world
2. Run the command below to move into the newly-created directory and create a new text file called helloworld.cs. This file will be our first C# application for the Mono Framework. This is a C# source code file containing our hello world C# application. This application will print the “Hello, World!” string to the console when the program is run. Furthermore, it defines the Main method, which tells the C# compiler where to start executing our program.
cd hello-world && sudo nano helloworld.cs
3. Copy and paste the following code into the created helloworld.cs file. Once you’re done, save the file and exit from the editor.
using System; public class helloworld { public static void Main(string[] args) { Console.WriteLine ("Hello World! This sample provided by Mono FrameWork!"); } }
Where:
4. Now that we have the source code for our hello world c# program, we need to compile it into an executable. Run the following command in the root of the directory that contains the helloworld.cs file.
csc helloworld.cs
This command will compile your C# application into an executable called “helloworld.exe” and place it in your current directory.
5. Run the ls command to list the contents of your current directory, and you should be able to see the “helloworld.exe” executable file listed there.
ls -la
6. Finally, we need to run this program on our Debian machine in order to test it out and make sure that everything is working properly. Use the mono command from your shell to run the helloworld.exe application that was created.
mono helloworld.exe
You will get the following output. Congratulations! You’ve successfully installed the Mono framework and created your first hello world application on your Debian Linux machine.
This guide taught you how to install Mono on Debian 10 and create your first hello world C# application. With this, you have a solid foundation to build Mono applications on every operating system that supports Linux. Thank you for your time, and happy coding! See also Microsoft net framework download for Windows.