Skip to content
Search

Mono

lastmod 2022-03-14created 2017-11-089 edits

Mono is a free and open-source project to develop Ecma standard and .NET Framework compatible tools, led by a C# compiler and a Common Language Runtime, and is currently directed by Novell. Mono is available on various Unix-like operating systems, led by Linux, BSD, Mac OS X, and OpenSolaris, and is also available on Windows.

In fact, Microsoft had already released a .NET-compatible open-source tool called Shared Source CLI (codename Rotor) that runs on FreeBSD and Mac OS X, but the license Microsoft applied to this tool contains a clause prohibiting commercial use, so although the tool is open source, it is not free software.

Registering the repository

Ubuntu 20.04 (amd64, armhf, arm64, ppc64el)

sudo apt install gnupg ca-certificates
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt update

Installation

Install Mono

sudo apt install mono-devel

Package list

  • The mono-devel package is needed to compile code.
  • The mono-complete package installs everything. This should cover most cases of "assembly not found" errors.
  • The mono-dbg package is needed to get debugging symbols for the framework libraries. This lets you get line numbers in stack traces.
  • The referenceassemblies-pcl package is needed for PCL compilation support. This resolves most "Framework not installed: .NETPortable" errors while compiling software.
  • The ca-certificates-mono package is needed to get SSL certificates for HTTPS connections. Install this package if you have problems with HTTPS connections.
  • The mono-xsp4 package is needed to run ASP.NET applications.

Mono Basics

using System;

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

Compile using the csc compiler:

csc hello.cs

Once the hello.exe file is created, run it with the mono command.

mono hello.exe

Troubleshooting

Gateway Timeout

On Ubuntu 20.04, after registering the repository, the following problem occurred while installing with the sudo apt install mono-devel command.

...

0 upgraded, 161 newly installed, 0 to remove and 8 not upgraded.
Need to get 41.4 kB/87.8 MB of archives.
After this operation, 383 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Err:1 https://download.mono-project.com/repo/ubuntu vs-focal/main amd64 libmono-parallel4.0-cil all 6.12.0.122-0xamarin1+ubuntu2004b1
  504  Gateway Timeout [IP: 117.18.232.200 443]
E: Failed to fetch https://download.mono-project.com/repo/ubuntu/pool/main/m/mono/libmono-parallel4.0-cil_6.12.0.122-0xamarin1+ubuntu2004b1_all.deb  504  Gateway Timeout [IP: 117.18.232.200 443]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

Only the libmono-parallel4.0-cil_6.12.0.122-0xamarin1+ubuntu2004b1_all.deb file hit a gateway timeout, so I downloaded just that package manually and installed it with dpkg. After that, reinstalling succeeded.

See also

Favorite site

author Zer0 sitemap