How to install Mono on CentOS 8
Mono is a software platform designed to develop and run cross-platform applications based on ECMA / ISO standards. It is a free open source project sponsored by Microsoft and supports many modern operating system architectures. Mono is used to create software that is compatible with the .NET framework and includes the C # compiler and the Common Language Runtime (CLR).
In this article, we will show you how to install Mono on CentOS 8 and how to write and compile your first C # program on Linux.
Prerequisites
You must be logged in as either sudo or root user on your CentOS system.
Installing Mono on CentOS 8
This is the recommended and easiest way to install Mono on CentOS 8, is to install it from the official repository. This is a fairly simple process that only takes a few minutes. To install Mono on CentOS 8, follow these steps:
Open a terminal by clicking Actions located in the upper left corner and click the terminal icon in the left sidebar of the application bar.
Import the GPG key
Install the required packages and start the installation by importing the GPG key of the required Mono repository. Run the command below to complete this step.
$ sudo rpm --import 'http://pool.sks-keyservers.net/pks/lookup?op=get&search=0x3fa7e0328081bff6a14da29aa6a19b38d3d831ef'
If successful, you will not see any messages on the terminal.
Add Mono repository
At this point, you need to add the Mono repository to your CentOS system by running the command below:
$ dnf config-manager --add-repo https://download.mono-project.com/repo/centos8-stable.repo
After running the above command, the Mono repository will be added to your system. On the terminal, you should see the following output:
Install Mono
After setting up the repository, install Mono on your system by running the following command in a terminal:
$ sudo dnf install mono-complete
Advertisement
Advertisement
Press “y” and then “Enter” to continue.
In the above command, “mono-complete” is used for the metapackage that installs all the development tools, libraries, and the Mono runtime.
Check Mono version
To check the installation of Mono on your system, run the following command, which displays the installed version of Mono:
$ mono --version
At the time of this writing, the latest available version of Mono is 6.12.0.90. As you can see in the following image, Mono was installed on our system:
Once Mono has finished installing, you can use it on CentOS 8.
Run C # sample code with Mono on CentOS
To verify that Mono is configured correctly, we create a C # test program to work with Mono and display the message “Test file for Hello World!” To do this, create a file named “helloworld.cs” using the touch command:
$ touch helloworld.cs
Open the above file in your favorite text editor and paste the following code into it:
using System; public class HelloWorld { public static void Main(string[] args) { Console.WriteLine ("Test file for Hello World!"); } }
Save the file and compile or build the above program using the csc compiler. Run the following command to create the above program:
$ csc helloworld.cs
The above command will create an executable named helloworld.exe.
Now start the program by running the following command in the terminal:
$ mono helloworld.exe
The terminal should display the following output:
You can run a program just by typing its name. To do this, you need to set the executable flag using the following command:
$ chmod +x helloworld.exe
You can now run the helloworld.exe file by typing the following command:
$ ./helloworld.exe
Output
In this article, we learned how to install Mono on CentOS 8. You can find the latest Mono release packages to install in the official Mono package repository. Feel free to leave us your feedback in case of any problems.
How to install Mono on CentOS 8