マルチプラットフォームでオープンソースな.NETの実行環境、Monoのインストール。 今回インストールしたバージョンは1.1.9.2。

前準備

yumを使ってインストールするため、/etc/yum.repos.d/の下にmono.repoというファイルを作成しておく。 ダウンロードページに書いてあるmono.repoだけだと、インストール時に

Package mono-xxxxxx-1.1.9.2-0.novell.i586.rpm is not signed

というメッセージが出てきてしまう。 面倒なので、ここでは左記のmono.repoに追記をしてgpgcheckをすべてにしておく。

# vi /etc/yum.repos.d/mono.repo 

[mono-1.1]
name=Mono 1.1 for fedora-$releasever-$basearch
baseurl=http://go-mono.com/download/mono-1.1/fedora-$releasever-$basearch/
enabled=1
gpgcheck=0

[gtk-sharp-1.0]
name=Gtk# 1.0 for fedora-$releasever-$basearch
baseurl=http://go-mono.com/download/gtk-sharp/fedora-$releasever-$basearch/
enabled=1
gpgcheck=0

[gtk-sharp-2.0]
name=Gtk# 2.0 for fedora-$releasever-$basearch
baseurl=http://go-mono.com/download/gtk-sharp-2.0/fedora-$releasever-$basearch/
enabled=1
gpgcheck=0

インストール

何も考えずにインストールするなら、以下の通りにすれば終わり。

# yum install -y mono-complete

ただこれだと、使わなそうなパッケージまでインストールされてしまうので、今回は以下のパッケージをインストールした。

mono-core
コアライブラリ、コレがないと動いてくれない。 CIL(MSIL)のためのJITコンパイラなどなど。
mono-basic
VB.NETコンパイラなどVB.NETのサポート。 今回はどんなものかお試しするために入れてみた。
mono-extras
なんかいろいろ入っているらしい。
mono-locale-extras
System.Text.EncodingでShift_JISやEUC-JPを使うのに必要(だったと思う)。

依存関係もあり、結局インストールされたのは以下のパッケージ(mono-data, mono-web, mono-winformsが依存関係にあるので追加されたパッケージ)。

=============================================================================
 Package                 Arch       Version          Repository        Size 
=============================================================================
Installing:
 mono-basic              i586       1.1.9.2-0.novell  mono-1.1          514 k
 mono-core               i586       1.1.9.2-0.novell  mono-1.1          9.9 M
 mono-extras             i586       1.1.9.2-0.novell  mono-1.1          207 k
 mono-locale-extras      i586       1.1.9.2-0.novell  mono-1.1          843 k
Installing for dependencies:
 mono-data               i586       1.1.9.2-0.novell  mono-1.1          1.7 M
 mono-web                i586       1.1.9.2-0.novell  mono-1.1          2.2 M
 mono-winforms           i586       1.1.9.2-0.novell  mono-1.1          2.1 M

GAC(/usr/lib/mono/gac)にインストールされたアセンブリは以下の通り。

# ls -l /usr/lib/mono/gac
drwxr-xr-x  4 root root 4096 11月  4 20:18 Accessibility
drwxr-xr-x  4 root root 4096 11月  4 20:18 Commons.Xml.Relaxng
drwxr-xr-x  4 root root 4096 11月  4 20:18 I18N
drwxr-xr-x  4 root root 4096 11月  4 20:18 I18N.CJK
drwxr-xr-x  4 root root 4096 11月  4 20:18 I18N.MidEast
drwxr-xr-x  4 root root 4096 11月  4 20:18 I18N.Other
drwxr-xr-x  4 root root 4096 11月  4 20:18 I18N.Rare
drwxr-xr-x  4 root root 4096 11月  4 20:18 I18N.West
drwxr-xr-x  4 root root 4096 11月  4 20:18 ICSharpCode.SharpZipLib
drwxr-xr-x  4 root root 4096 11月  4 20:18 Microsoft.VisualBasic
drwxr-xr-x  4 root root 4096 11月  4 20:18 Microsoft.VisualC
drwxr-xr-x  4 root root 4096 11月  4 20:18 Microsoft.Vsa
drwxr-xr-x  3 root root 4096 11月  4 20:18 Mono.C5
drwxr-xr-x  4 root root 4096 11月  4 20:18 Mono.Cairo
drwxr-xr-x  4 root root 4096 11月  4 20:18 Mono.CompilerServices.SymbolWriter
drwxr-xr-x  4 root root 4096 11月  4 20:18 Mono.Data
drwxr-xr-x  4 root root 4096 11月  4 20:18 Mono.Data.Tds
drwxr-xr-x  4 root root 4096 11月  4 20:18 Mono.Data.TdsClient
drwxr-xr-x  4 root root 4096 11月  4 20:18 Mono.GetOptions
drwxr-xr-x  4 root root 4096 11月  4 20:18 Mono.Http
drwxr-xr-x  4 root root 4096 11月  4 20:18 Mono.Posix
drwxr-xr-x  4 root root 4096 11月  4 20:18 Mono.Security
drwxr-xr-x  4 root root 4096 11月  4 20:18 Novell.Directory.Ldap
drwxr-xr-x  4 root root 4096 11月  4 20:18 System
drwxr-xr-x  3 root root 4096 11月  4 20:18 System.Configuration
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.Configuration.Install
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.Data
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.Design
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.DirectoryServices
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.Drawing
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.Drawing.Design
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.EnterpriseServices
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.Management
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.Messaging
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.Runtime.Remoting
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.Runtime.Serialization.Formatters.Soap
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.Security
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.ServiceProcess
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.Web
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.Web.Services
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.Windows.Forms
drwxr-xr-x  4 root root 4096 11月  4 20:18 System.Xml
drwxr-xr-x  4 root root 4096 11月  4 20:18 cscompmgd

動作確認

バージョンを確認する。 まずはmono本体。

# mono --version
Mono JIT compiler version 1.1.9.2, (C) 2002-2005 Novell, Inc and Contributors. www.mono-project.com
        TLS:           normal
        GC:            Included Boehm (with typed GC)
        SIGSEGV      : normal
        Globalization: normal

続いてC#コンパイラであるmcs。

# mcs --version
Mono C# compiler version 1.1.9.1

最後にVB.NETコンパイラであるmbas。

# mbas -about
MonoBASIC Compiler  0.96.2.0 - (c)2002, 2003, 2004, 2005 Rafael Teixeira
--------
THIS IS AN ALPHA SOFTWARE.
--------
This is a compiler for the MonoBASIC language, 
which is a superset of Visual Basic.NET

Distributed under the GPL 2.0
Authors: Ravi Pratap, Miguel de Icaza, Rafael Teixeira, Marco Ridoni, Martin Baulig, Anirban Bhattacharjee, Manjula GHM, Satya Sudha K, Sudharsan V

続いて、コンパイルしたものが動作するかお試ししてみる。 まずはC#。

# vi test.cs

using System;

public class Test
{
        public static void Main()
        {
                Console.WriteLine( "Hello mcs!!" );
        }
}

# mcs test.cs 
# mono test.exe 
Hello mcs!!

mcsは問題なくコンパイルが終わっても何も言ってくれないけど、ひとまずよさげ。 続いてVB.NET。

# vi  test.bas 

Option Explicit On

Imports System

Public Class Test

        Public Shared Sub Main()

                Console.WriteLine( "Hello mbas!!" )

        End Sub

End Class

# mbas test.bas 
MonoBASIC Compiler  0.96.2.0 - (c)2002, 2003, 2004, 2005 Rafael Teixeira
--------
THIS IS AN ALPHA SOFTWARE.
--------
Compilation succeeded
# mono test.exe 
Hello mbas!!

これもよさげ。 上記のように、mbasは、ちゃんとうまくいったよと教えてくれる。