Install Mono on Ubuntu 20.04 LTS

Install Mono on Ubuntu 20.04 LTS

Today in this tutorial we are going to Learn How to Install Mono on Ubuntu 20.04 LTS and Ubuntu 21.04, Mono is a platform for development and running cross-platform multi-system applications based on ECMA and ISO Standards. It is a free and open-source implementation of the Microsoft .NET framework.

In this quick guide and tutorial, I’m explains how to install Mono on Ubuntu 20.04 and Ubuntu 21.04

Precondition for install Mono on Ubuntu

The instructions assume that you are logged in as root or a privileged user sudo.

Install Mono on Ubuntu 20.04 LTS

The easiest and recommended way to install Mono on Ubuntu 18.04 is to install it from the Mono repository. This is a relatively easy process and will only take a few minutes.

Start by installing the required packages:

sudo apt update 
sudo apt install dirmngr gnupg apt-transport-https ca-certificates

Import the GPG key from the repository using the following command:

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

The output will look like this:

gpg: key A6A19B38D3D831EF: public key "Xamarin Public Jenkins (auto-signing) " imported 
gpg: Total number processed: 1 
gpg:               imported: 1

Add the Mono repository to sources list your system’s by running the command below:

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

Once the apt repository is enabled, update the package list and install Mono with:

sudo apt update 
sudo apt install mono-complete 

Mono-complete is a meta package that installs the Mono runtime, development tools and all mono libraries.

Verify the installation by typing the following command which will print the Mono version:

mono –version

At the time of writing this article, the latest stable version of Mono is 6.6.0 Stable (6.6.0.161).

Mono JIT compiler version 6.6.0.161 (tarball Tue Dec 10 10:36:32 UTC 2019) 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 Ubuntu, and you can start using it.

Start Mono with Hello World

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

Open the text editor nano and create a file named hello.cs with the following content:

nano hello.cs 
using System;

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

Use cscto build the program:

csc hello.cs 

The above command will build an executable named hello.exe.

Run the executable using the command below:

mono hello.exe 

The output will look like this:

Hello, World 

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

chmod +x hello.exe 

You can now run the file hello.exeby typing:

./hello.exe 

Conclusion

In this tutorial we learned How to install mono on Ubuntu 20.04 LTS and Ubuntu 21.04, The latest stable Mono release packages are available for installation from the official Mono package repositories.

Some Related Post :

How To Install and configure Nginx in Ubuntu 20.04 and Ubuntu 21.04

How to Install Google Chrome on Ubuntu 20.04 and Ubuntu 21.04

How to Install and Configure OpenCV on Rocky Linux 8.4

Be the first to comment

Leave a Reply

Your email address will not be published.


*