Table of Contents
In this article, I will take you through 8 Popular Steps to Install Mono on RedHat/CentOS 7. Mono is a popular tool in Linux platform used for compiling and executing C# Program. This tool helps Microsoft C# Professionals to write and execute C# code in Linux Platform.
Install Mono on CentOS 7
Also Read: 6 Useful C# For Loop Examples
Step 1: Prerequisites
a)You require a running RedHat/CentOS 7 System.
b)You need to have sudo access. You can check Step By Step: How to add User to Sudoers into Ubuntu 18.04 to provide sudo access to User.
Step 2: Update Your System
First you need to update your system before proceeding with the next step using yum -y update
command.
[root@localhost ~]# yum -y update Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.piconets.webwerks.in * epel: mirrors.piconets.webwerks.in * extras: mirrors.piconets.webwerks.in * updates: mirrors.piconets.webwerks.in Resolving Dependencies --> Running transaction check ---> Package NetworkManager.x86_64 1:1.18.0-5.el7_7.1 will be updated ---> Package NetworkManager.x86_64 1:1.18.0-5.el7_7.2 will be an update ---> Package NetworkManager-libnm.x86_64 1:1.18.0-5.el7_7.1 will be updated ---> Package NetworkManager-libnm.x86_64 1:1.18.0-5.el7_7.2 will be an update ---> Package NetworkManager-team.x86_64 1:1.18.0-5.el7_7.1 will be updated ---> Package NetworkManager-team.x86_64 1:1.18.0-5.el7_7.2 will be an update ---> Package NetworkManager-tui.x86_64 1:1.18.0-5.el7_7.1 will be updated ---> Package NetworkManager-tui.x86_64 1:1.18.0-5.el7_7.2 will be an update ---> Package binutils.x86_64 0:2.27-41.base.el7_7.1 will be updated ---> Package binutils.x86_64 0:2.27-41.base.el7_7.3 will be an update ---> Package curl.x86_64 0:7.29.0-54.el7_7.1 will be updated ---> Package curl.x86_64 0:7.29.0-54.el7_7.2 will be an update ---> Package docker.x86_64 2:1.13.1-103.git7f2769b.el7.centos will be updated ---> Package docker.x86_64 2:1.13.1-109.gitcccb291.el7.centos will be an update ---> Package docker-client.x86_64 2:1.13.1-103.git7f2769b.el7.centos will be updated ---> Package docker-client.x86_64 2:1.13.1-109.gitcccb291.el7.centos will be an update ---> Package docker-common.x86_64 2:1.13.1-103.git7f2769b.el7.centos will be updated ---> Package docker-common.x86_64 2:1.13.1-109.gitcccb291.el7.centos will be an update ---> Package epel-release.noarch 0:7-11 will be updated ---> Package epel-release.noarch 0:7-12 will be an update ---> Package firewalld.noarch 0:0.6.3-2.el7_7.2 will be updated ---> Package firewalld.noarch 0:0.6.3-2.el7_7.4 will be an update
Step 3: Install Yum Utils Packages
Now you need to install yum-utils
package using yum install -y yum-utils
command as shown below. This package will install yum-config-manager
tool which is required for adding mono repository.
[root@localhost ~]# yum install -y yum-utils Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.piconets.webwerks.in * epel: mirrors.piconets.webwerks.in * extras: mirrors.piconets.webwerks.in * updates: mirrors.piconets.webwerks.in Resolving Dependencies --> Running transaction check ---> Package yum-utils.noarch 0:1.1.31-52.el7 will be installed --> Processing Dependency: python-kitchen for package: yum-utils-1.1.31-52.el7.noarch --> Processing Dependency: libxml2-python for package: yum-utils-1.1.31-52.el7.noarch --> Running transaction check ---> Package libxml2-python.x86_64 0:2.9.1-6.el7_2.3 will be installed ---> Package python-kitchen.noarch 0:1.1.1-5.el7 will be installed --> Processing Dependency: python-chardet for package: python-kitchen-1.1.1-5.el7.noarch --> Running transaction check ---> Package python-chardet.noarch 0:2.2.1-3.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================== Package Arch Version Repository Size ======================================================================================================================================================================== Installing: yum-utils noarch 1.1.31-52.el7 base 121 k Installing for dependencies: libxml2-python x86_64 2.9.1-6.el7_2.3 base 247 k python-chardet noarch 2.2.1-3.el7 base 227 k python-kitchen noarch 1.1.1-5.el7 base 267 k Transaction Summary ======================================================================================================================================================================== Install 1 Package (+3 Dependent packages) Total download size: 862 k Installed size: 4.3 M Downloading packages: (1/4): python-kitchen-1.1.1-5.el7.noarch.rpm | 267 kB 00:00:00 (2/4): yum-utils-1.1.31-52.el7.noarch.rpm | 121 kB 00:00:00 (3/4): libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm | 247 kB 00:00:00 (4/4): python-chardet-2.2.1-3.el7.noarch.rpm | 227 kB 00:00:00 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Total 1.0 MB/s | 862 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : python-chardet-2.2.1-3.el7.noarch 1/4 Installing : python-kitchen-1.1.1-5.el7.noarch 2/4 Installing : libxml2-python-2.9.1-6.el7_2.3.x86_64 3/4 Installing : yum-utils-1.1.31-52.el7.noarch 4/4 Verifying : python-kitchen-1.1.1-5.el7.noarch 1/4 Verifying : yum-utils-1.1.31-52.el7.noarch 2/4 Verifying : libxml2-python-2.9.1-6.el7_2.3.x86_64 3/4 Verifying : python-chardet-2.2.1-3.el7.noarch 4/4 Installed: yum-utils.noarch 0:1.1.31-52.el7 Dependency Installed: libxml2-python.x86_64 0:2.9.1-6.el7_2.3 python-chardet.noarch 0:2.2.1-3.el7 python-kitchen.noarch 0:1.1.1-5.el7 Complete!
Step 4: Add Repo
Now that you have installed yum-config-manager
, you need to add the Mono repository using yum-config-manager
to download the mono packages as shown in below command.
[root@localhost ~]# yum-config-manager --add-repo http://download.mono-project.com/repo/centos/ Loaded plugins: fastestmirror adding repo from: http://download.mono-project.com/repo/centos/ [download.mono-project.com_repo_centos_] name=added from: http://download.mono-project.com/repo/centos/ baseurl=http://download.mono-project.com/repo/centos/ enabled=1
Step 5: Clear Older YUM Cache
We can clear old yum cache and remove all previous yum leftover using yum clean all
command as shown below.
[root@localhost ~]# yum clean all Loaded plugins: fastestmirror Cleaning repos: base download.mono-project.com_repo_centos_ epel extras kubernetes nodesource puppetlabs-pc1 updates Cleaning up list of fastest mirrors
Step 6: Build Up New YUM Cache
Once everything is cleared from the cache, then we can build new cache using yum makecache
command as shown below.
[root@localhost ~]# yum makecache Loaded plugins: fastestmirror Determining fastest mirrors epel/x86_64/metalink | 8.6 kB 00:00:00 * base: mirrors.piconets.webwerks.in * epel: mirrors.piconets.webwerks.in * extras: mirrors.piconets.webwerks.in * updates: mirrors.piconets.webwerks.in base | 3.6 kB 00:00:00 download.mono-project.com_repo_centos_ | 2.9 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 2.9 kB 00:00:00 kubernetes/signature | 454 B 00:00:00 kubernetes/signature | 1.4 kB 00:00:00 !!! nodesource | 2.5 kB 00:00:00 puppetlabs-pc1 | 2.5 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/28): base/7/x86_64/group_gz | 165 kB 00:00:00 (2/28): download.mono-project.com_repo_centos_/primary_db | 1.5 MB 00:00:01 (3/28): base/7/x86_64/primary_db | 6.0 MB 00:00:02 (4/28): base/7/x86_64/other_db | 2.6 MB 00:00:02 (5/28): download.mono-project.com_repo_centos_/other_db | 114 kB 00:00:01 (6/28): epel/x86_64/group_gz | 95 kB 00:00:00 (7/28): epel/x86_64/prestodelta | 75 B 00:00:00 (8/28): base/7/x86_64/filelists_db | 7.3 MB 00:00:05 (9/28): epel/x86_64/primary_db | 6.8 MB 00:00:03 (10/28): extras/7/x86_64/filelists_db | 217 kB 00:00:00 (11/28): extras/7/x86_64/primary_db | 165 kB 00:00:00 (12/28): extras/7/x86_64/other_db | 106 kB 00:00:00 (13/28): download.mono-project.com_repo_centos_/filelists_db | 984 kB 00:00:07 (14/28): epel/x86_64/other_db | 3.2 MB 00:00:01 (15/28): epel/x86_64/updateinfo | 1.0 MB 00:00:05 (16/28): kubernetes/filelists | 22 kB 00:00:01 (17/28): kubernetes/primary | 66 kB 00:00:01 (18/28): nodesource/x86_64/primary_db | 25 kB 00:00:00 (19/28): nodesource/x86_64/filelists_db | 342 kB 00:00:00 (20/28): kubernetes/other | 42 kB 00:00:00 (21/28): nodesource/x86_64/other_db | 3.4 kB 00:00:00 (22/28): puppetlabs-pc1/x86_64/primary_db | 234 kB 00:00:00 (23/28): puppetlabs-pc1/x86_64/other_db | 13 kB 00:00:00 (24/28): updates/7/x86_64/other_db | 573 kB 00:00:00 (25/28): updates/7/x86_64/filelists_db | 4.5 MB 00:00:01 (26/28): puppetlabs-pc1/x86_64/filelists_db | 7.6 MB 00:00:04 (27/28): epel/x86_64/filelists_db | 11 MB 00:00:13 (28/28): updates/7/x86_64/primary_db | 7.6 MB 00:00:08 kubernetes 481/481 kubernetes 481/481 kubernetes 481/481 Metadata Cache Created
Step 7: Install Mono
You can install mono using yum install -y mono-complete
command as shown below.
[root@localhost ~]# yum install -y mono-complete Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.piconets.webwerks.in * epel: mirrors.piconets.webwerks.in * extras: mirrors.piconets.webwerks.in * updates: mirrors.piconets.webwerks.in Resolving Dependencies --> Running transaction check ---> Package mono-complete.x86_64 0:6.8.0.105-0.xamarin.3.epel7 will be installed --> Processing Dependency: mono-data-sqlite = 6.8.0.105 for package: mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: libmonosgen-2_0-devel = 6.8.0.105 for package: mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: install mono = 6.8.0.105 for package: mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: mono-reactive = 6.8.0.105 for package: mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: libmonoboehm-2_0-devel = 6.8.0.105 for package: mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: libmonoboehm-2_0-1 = 6.8.0.105 for package: mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: mono-wcf = 6.8.0.105 for package: mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: libmono-llvm0 = 6.8.0.105 for package: mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: mono-web = 6.8.0.105 for package: install mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: mono-extras = 6.8.0.105 for package: install mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: monodoc-core = 6.8.0.105 for package: install mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: ibm-data-db2 = 6.8.0.105 for package: mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: libmonosgen-2_0-1 = 6.8.0.105 for package: mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: mono-locale-extras = 6.8.0.105 for package: mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: libmono-2_0-1 = 6.8.0.105 for package: mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: libmono-2_0-devel = 6.8.0.105 for package: install mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: mono-mvc = 6.8.0.105 for package: install mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: mono-winfxcore = 6.8.0.105 for package: install mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: mono-data-oracle = 6.8.0.105 for package: install mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: mono-data = 6.8.0.105 for package: install mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: mono-core = 6.8.0.105 for package: install mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 --> Processing Dependency: mono-devel = 6.8.0.105 for package: install mono-complete-6.8.0.105-0.xamarin.3.epel7.x86_64 Installed: mono-complete.x86_64 0:6.8.0.105-0.xamarin.3.epel7 Dependency Installed: glib2-devel.x86_64 0:2.56.1-5.el7 ibm-data-db2.x86_64 0:6.8.0.105-0.xamarin.3.epel7 libexif.x86_64 0:0.6.21-6.el7 libgdiplus-devel.x86_64 0:6.0.4-0.xamarin.1.epel7 libgdiplus0.x86_64 0:6.0.4-0.xamarin.1.epel7 libmono-2_0-1.x86_64 0:6.8.0.105-0.xamarin.3.epel7 libmono-2_0-devel.x86_64 0:6.8.0.105-0.xamarin.3.epel7 libmono-llvm0.x86_64 0:6.8.0.105-0.xamarin.3.epel7 libmonoboehm-2_0-1.x86_64 0:6.8.0.105-0.xamarin.3.epel7 libmonoboehm-2_0-devel.x86_64 0:6.8.0.105-0.xamarin.3.epel7 libmonosgen-2_0-1.x86_64 0:6.8.0.105-0.xamarin.3.epel7 libmonosgen-2_0-devel.x86_64 0:6.8.0.105-0.xamarin.3.epel7 mono-core.x86_64 0:6.8.0.105-0.xamarin.3.epel7 install mono-data.x86_64 0:6.8.0.105-0.xamarin.3.epel7 mono-data-oracle.x86_64 0:6.8.0.105-0.xamarin.3.epel7 install mono-data-sqlite.x86_64 0:6.8.0.105-0.xamarin.3.epel7 mono-devel.x86_64 0:6.8.0.105-0.xamarin.3.epel7 mono-extras.x86_64 0:6.8.0.105-0.xamarin.3.epel7 mono-llvm-tools.x86_64 0:6.0+mono20190708165219-0.xamarin.1.epel7 mono-locale-extras.x86_64 0:6.8.0.105-0.xamarin.3.epel7 mono-mvc.x86_64 0:6.8.0.105-0.xamarin.3.epel7 mono-reactive.x86_64 0:6.8.0.105-0.xamarin.3.epel7 mono-wcf.x86_64 0:6.8.0.105-0.xamarin.3.epel7 mono-web.x86_64 0:6.8.0.105-0.xamarin.3.epel7 mono-winforms.x86_64 0:6.8.0.105-0.xamarin.3.epel7 mono-winfxcore.x86_64 0:6.8.0.105-0.xamarin.3.epel7 monodoc-core.x86_64 0:6.8.0.105-0.xamarin.3.epel7 msbuild.noarch 1:16.5+xamarinxplat.2020.01.10.05.36-0.xamarin.2.epel7 msbuild-libhostfxr.x86_64 0:3.0.0.2019.04.16.02.13-0.xamarin.4.epel7 msbuild-sdkresolver.noarch 1:16.5+xamarinxplat.2020.01.10.05.36-0.xamarin.2.epel7 pcre-devel.x86_64 0:8.32-17.el7 unzip.x86_64 0:6.0-20.el7 Complete!
If you see any key error during or after installation, then you can use below command to import the key.
rpm --import "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"
Step 8: Write Your First C# Program
Once mono is successfully installed, we can now write a small program to test the installation. In this program, we are displaying "Hello World!"
in the Console Output.
[root@localhost ~]# vi hello.cs public class HelloWorld { public static void Main() { System.Console.WriteLine("Hello, World!"); } }
Compile Your Program
You can compile hello.cs program using mcs hello.cs
command as specified below.
[root@localhost ~]# mcs hello.cs
Run Your Program
Now you can run your program using mono hello.exe
command and check the output.
[root@localhost ~]# mono hello.exe Hello, World!
Thnaks. very complete guide