How To

Install Mono on Ubuntu 18.04: C# Compiler and Runtime Guide

Running programs built for Microsoft’s framework on a Linux system is easier than you think. Mono is an open source framework that implements the C# language and compiles .NET tools to run on Unix platforms. It allows developers to run .NET applications on Linux servers.

This guide will show you how to install Mono on Ubuntu 18.04, compile a basic script, and manage your setup.

Set Up the Mono Project Repository

The default Ubuntu software sources may contain outdated versions of the framework. We will add the official repository to get the latest stable package.

First, install the secure connection certificates:

bashsudo apt install gnupg ca-certificates

Import the official GPG verification key:

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

Add the repository URL to your software list:

bashecho "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list

Update your local packages to import the new metadata:

bashsudo apt update

Install Mono Packages on Ubuntu

Now we can install the framework packages. The complete package contains the runtime, standard libraries, and development compilers.

Install the complete bundle:

bashsudo apt install mono-complete

Verify that the installation was successful by checking the framework version:

bashmono --version

The output will display the Mono JIT compiler version number to confirm everything is set up.

Compile and Run a C# Program

Let us write a simple test application to confirm the compiler works properly.

Open a text editor and create a new C# file named hello.cs:

csharpusing System;class Hello {    static void Main() {        Console.WriteLine("Hello from Mono on Ubuntu!");    }}

Save the file. Run the C# compiler to compile your script:

bashmcs hello.cs

The compiler will create an executable file named hello.exe in the same directory.

Run the executable program using the runtime:

bashmono hello.exe

The terminal will print the message from the program, showing that the system is configured correctly.

Understand What Mono Can Do

Adding the Mono package opens up several development possibilities:

  • Run existing Windows executables on your server without rewriting the code
  • Compile new applications using standard C# syntax
  • Access cross-platform .NET libraries using package managers
  • Run backend ASP.NET applications on Linux web hosts

You have successfully installed the Mono framework on your Ubuntu machine. You can now build and run C# programs. Leave a comment below if you have any questions or run into any compiler warnings.

Cyber Defence

Recent Posts

Install OpenCV on Ubuntu 18.04: Step-by-Step Setup Guide

Computer vision technology powers many modern applications, from image editors to facial scanners. OpenCV (Open Source Computer…

17 minutes ago

Install VNC on Ubuntu 18.04: Step-by-Step TigerVNC Setup

A remote desktop interface makes it easy to manage a remote computer. VNC (Virtual Network Computing) is…

35 minutes ago

Install Gitea on Ubuntu 18.04: Self-Hosted Git Service Guide

Hosting your own code repositories is a great way to keep your projects private. Gitea is a…

48 minutes ago

Install Java on Ubuntu 18.04: OpenJDK 11 and OpenJDK 8

Many modern programs require Java to run. From development tools like Eclipse to search systems…

57 minutes ago

Configure a Static IP Address on Ubuntu 18.04: Netplan Guide

Setting a static IP address on your server is a smart move. It ensures your…

24 hours ago

Install Xrdp on Ubuntu 18.04: Remote Desktop Setup Guide

Xrdp is an open-source implementation of the Microsoft Remote Desktop Protocol (RDP). It lets you access…

1 day ago