18.6 C
Jaipur
Sunday, November 28, 2021

How to Install Mono on Debian 11

Must read

Mono is an open-source platform for developing applications and libraries. It has been developed by Novell Inc. since 2002, with a focus on the .NET framework developed by Microsoft. Mono is most popularly used for developing cross-platform tools and applications integrated with .NET technologies.

Mono provides a complete CLR (Common Language Runtime) implementation that can run class libraries or components that target Microsoft’s original .NET runtime. These class libraries are compatible with any system that has a recent version of Mono installed, including Linux, Mac OS X, Windows, Solaris, BSDs, etc. On iOS, MonoTouch is used for building iOS apps, and on Android, it can be used to write programs that run on Android devices.

Mono provides .NET Framework compatibility for non-Windows platforms at both the library level and the application programming interface (API) level. This means that programs written for Microsoft .NET on Windows will also run on Mono on other platforms supported by Mono with minimal or no recoding.

Mono-complete Linux refers to an operating system which uses the mono framework as its main platform for application development, including the ability to run Microsoft .NET Framework executables using Mono’s Xamarin tool. Mono-complete Linux can be installed alongside other operating systems on a computer or it may replace them entirely, depending on user preference.

Prerequisites

In order to install Mono on Debian 11, the following prerequisites should be met:

  • A server running Debian 11 with a working internet connection.
  • An account with sudo privileges.

Updating the System

It’s important to update the system before proceeding. Run the following commands one by one to update your system.

sudo apt-get update
sudo apt-get upgrade -y

Once the system is updated, run the following command to install the required dependencies.

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

Before installing Mono, it’s a good idea to make sure that any previous versions of Mono have been removed from your system. The existing versions may conflict with the new version or produce unexpected results during the installation process.

To remove Mono, run the following command.

sudo apt remove --purge --auto-remove mono-runtime

Installing Mono

Now that your system is up to date and any previous versions of Mono have been removed, you can begin the installation process.

To get started with the download, run the following command to add the Mono GPG key to your system.

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

With the GPG key added to the system, you can add the Mono repository, which provides the latest officially supported Mono package with the following command.

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

Now update the system using the following command.

sudo apt-get update

Run the following command to check if mono is in your local repositories.

sudo apt search mono

The command will search the mono package in all available repositories and prints its result as shown below.

To install mono, run the following command.

sudo apt-get install mono-complete -y

To check if Mono is successfully installed on your system, run the following command.

mono --version

The output of this command should be a version number corresponding with the latest version of Mono as shown below.

Installing Mono

You can also run the command below to check the mono-complete package installed on your system.

sudo apt-cache policy mono-complete

The output of this command should be similar to the one shown below.

The above installation is a basic one, and you can also install other dependencies that might be required for your system. Feel free to check the official documentation for more information.

Testing the Mono Installation

Now that Mono is installed on your Debian system, you can test its installation by creating a simple Mono application, compiling it, and executing it using Mono.

To create a simple Mono application, open your favorite text editor, and create a new file with the name hello.cs. We will use the nano text editor to create the file i this example.

sudo nano hello.cs

Add the following lines of code to the file.

using System;

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

Where:

  • using System: This directive tells the compiler to include mscorlib, which provides types and entry points that are required for most class library program development.
  • public class HelloWorld: This is a class named “HelloWorld” derived from the class called “Object”. This means that HelloWorld will have Object’s instance variables, instance methods, static members, etc.
  • public static void Main: This method is special because it is the entry point for every C# program and returns nothing. The string[] args means this method takes an array of strings as parameters.
  • Console.WriteLine(“Hello World!”);: Just prints Hello World! to the console screen.

After creating the file, save and exit the file by pressing CTRL+X, Y, then Enter.

Now you have created the C# code file to be compiled into a .exe using Mono, so now it’s time to compile the code into bytecode. To do that, run the following command.

mono-csc hello.cs

The above command tells mono -csc to compile hello.cs using the Mono compiler, which takes the source code and generates a .exe file from it. You can use the ls command to view the newly created file.

ls -l *.exe

If everything was successful, you should see an executable named “hello”, as shown in the screenshot below.

Testing the Mono Installation

In order to execute the program, run the mono command with the filename as a parameter.

mono hello.exe

This command will print Hello World! on your console, which you can see in the screenshot below.

Testing the Mono Installation

Conclusion

Now that Mono has been installed in your system, you can go ahead and create C# applications. Feel free to check the official documentation for more information. We hope this article will help you to install Mono on your system without any hiccups.

Leave your questions and feedback in the comments section below. 

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -

Latest article