How To Install and Use Mono on Centos 7

In this guide, we want to teach you How To Install and Use Mono on Centos 7.

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 Use Mono on Centos 7

To install Mono, 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 Centos 7.

Now you can follow the steps below to complete this guide.

Install Mono Software on Centos 7

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 Centos 7 with the command below:

su -c 'curl https://download.mono-project.com/repo/centos7-stable.repo | tee /etc/yum.repos.d/mono-centos7-stable.repo'
Output
[mono-centos7-stable]
name=mono-centos7-stable
baseurl=https://download.mono-project.com/repo/centos7-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 yum update -y

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

sudo yum 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:42:51 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)

Test Your Mono Installation

At this point, that you have Mono installed on your server, you can create a test application to see that Mono working correctly on Centos 7.

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!

That’s it. You are Done.

Conclusion

At this point, you learn to Install and Use Mono on Centos 7.

Hope you enjoy it.

You may be interested in these articles:

How To Add Swap on Centos 7

Install and Configure Nagios on Centos 7

How To Install Slack on Centos 7

Install and Configure Postfix Mail Server on Centos 7

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *

Stay informed and not overwhelmed, subscribe now!