How To Install and Configure Mono on Rocky Linux 8

In this guide, we want to teach you How To Install and Configure Mono on Rocky Linux 8.

Mono is a software platform designed to allow developers to easily create cross-platform applications part of the.NET Foundation. Sponsored by Microsoft, Mono is an open-source implementation of Microsoft’s.NET Framework based on the ECMA standards for C# and the Common Language Runtime.

How To Install and Configure Mono on Rocky Linux 8

To install MonoDevelop, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Rocky Linux 8.

Set up Mono on Rocky Linux 8

First, you need to import the GPG keys for Mono with the following command:

rpmkeys --import "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"

Then, you need to add the Mono repository on Rocky Linux 8 with the command below:

su -c 'curl https://download.mono-project.com/repo/centos8-stable.repo | tee /etc/yum.repos.d/mono-centos8-stable.repo'
Output
[mono-centos8-stable]
name=mono-centos8-stable
baseurl=https://download.mono-project.com/repo/centos8-stable/
enabled=1
gpgcheck=1
gpgkey=https://download.mono-project.com/repo/xamarin.gpg

Next, you need to update your local package index with the following command:

sudo dnf update -y

At this point, you can use the following command to install Mono on your server:

sudo dnf install mono-complete

The package mono-complete should be installed to install everything – this should cover most cases of “assembly not found” errors.

You can verify your Mono installation by checking its version:

mono --version

In your output you will see:

Output
Mono JIT compiler version 6.12.0.107 (tarball Wed Dec 9 21:44:58 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)

At this point, you have successfully installed Mono on Rocky Linux 8, you can start using it.

Create a Test Program with Mono on Rocky Linux 8

To verify that everything is set up correctly, we will create a program that will print the classic “hello world” message.

First, create a file named hello.cs with your favorite text editor, here we use vi:

sudo vi hello.cs

Add the following content to the file:

using System;

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

Use CSC to build the program:

sudo csc hello.cs
Output
Microsoft (R) Visual C# Compiler version 3.6.0-4.20224.5 (ec77c100)
Copyright (C) Microsoft Corporation. All rights reserved.

This command will build an executable named hello.exe.

Run the executable file with the following command:

sudo mono hello.exe

In your output you will see:

Output
Hello World!

Note: If you want to run a program by simply typing its name, you must set a flag to make it executable with the chmod command :

sudo chmod +x hello.exe

You can now run the file hello.exeby typing:

sudo ./hello.exe

Conclusion

At this point, you learn to Install and Configure Mono on Rocky Linux 8 and basic usage of it.

Hope you enjoy it.

Please subscribe to us on Facebook and Twitter.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!