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

xargs Command in Linux: Build and Execute Commands from Input

The xargs command in Linux reads items from standard input and passes them as arguments to another…

1 day ago

locate Command in Linux: Find Files Fast with a Database Search

The locate command in Linux searches for files and directories by name. It queries a pre-built database…

1 day ago

Listing Linux Services with systemctl: A Complete Guide

Most modern Linux distributions use systemd as the default service manager. Knowing how to list…

1 day ago

How to Truncate Files in Linux: Empty Files Without Deleting

Truncating a file in Linux means removing its contents while leaving the file itself in…

1 day ago

ss Command in Linux: Display Socket Statistics and Connections

The ss command in Linux lists open sockets and active network connections. It replaced the deprecated netstat command and…

2 days ago

ftp Command in Linux: Connect to Servers and Transfer Files

The ftp command in Linux connects to a remote FTP server and transfers files. FTP transmits everything…

2 days ago