CentOs8にmonoをインストールする

CentOs8にmonoをインストールする

.NET Framework互換言語である「mono」をcentos8にインストールする手順です。C#で記述したコードを実行するところまで、記述してます。

環境

  • OS  CentOS Linux release 8.0.1905 (Core)
  • mono 6.8.0.105

リポジトリ追加

monoのリポジトリを追加するため、 GPGキーをインポートします。

sudo rpm --import 'http://pool.sks-keyservers.net/pks/lookup?op=get&search=0x3fa7e0328081bff6a14da29aa6a19b38d3d831ef'

リポジトリを追加します。

sudo dnf config-manager --add-repo https://download.mono-project.com/repo/centos8-stable.repo

Monoインストール

すべてのライブラリをインストールします。

sudo dnf install mono-complete 

バージョンを確認します。

mono --version

<出力結果>
Mono JIT compiler version 6.8.0.105 (tarball Tue Feb  4 19:28:42 UTC 2020)
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)

実行

C#で書いたコードを実行してみます。下記のコードをhello.csと名前で保存します。

vi hello.cs
using System;

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

コンパイルします。

csc hello.cs

<出力結果>
Microsoft (R) Visual C# Compiler version 3.5.0-beta1-19606-04 (d2bd58c6)
Copyright (C) Microsoft Corporation. All rights reserved.

実行します。

 mono hello.exe

<出力結果>
Hello World!