Mono 3.0をソースからビルドしてインストールする手順。 検証に使った環境はUbuntu 12.04 (Precise Pangolin)。
ディストリビューションが提供しているバージョンのMonoと共存できるようにするため、/opt/mono/3.0にインストールする。
1つの環境に複数のMonoをインストールする方法についてはParallel Mono Environments - Monoで詳しく解説されている。
ビルドにはgcc、libtool、autotools、gettext、pkg-config等が必要になるので、あらかじめインストールしておく必要がある。
libgdiplus
依存するパッケージのインストール
sudo apt-get install \
libcairo2-dev libexif-dev libfreetype6-dev libfontconfig1-dev libglib2.0-dev libjpeg8-dev libpng12-dev \
libtiff4-dev libgif-dev libx11-dev libxrender-dev
ソースのダウンロードとconfigure
Mono 3.0リリース時点では3.0にバージョン付けされたlibgdiplusはリリースされていないため、現時点で最新の2.10.9を使用する。
wget http://download.mono-project.com/sources/libgdiplus/libgdiplus-2.10.9.tar.bz2
tar -xvf libgdiplus-2.10.9.tar.bz2
cd libgdiplus-2.10.9/
./configure --prefix=/opt/mono/3.0/
configureの結果例。
--- Configuration summary * Installation prefix = /opt/mono/3.0 * Cairo = 1.10.2 (system) * Text = cairo * EXIF tags = yes * Codecs supported: - TIFF: yes - JPEG: yes - GIF: yes - PNG: yes NOTE: if any of the above say 'no' you may install the corresponding development packages for them, rerun autogen.sh to include them in the build. ---
ビルド、インストール
configureした結果に問題が無ければmake、make installする。
make
sudo make install
正しくインストールできたか確認する。
ls -l /opt/mono/3.0/lib/libgdiplus*
Mono本体(コンパイラ、クラスライブラリ)
依存するパッケージのインストール
sudo apt-get install \
bison
ソースのダウンロードとconfigure
wget http://download.mono-project.com/sources/mono/mono-3.0.12.tar.bz2
tar -xvf ./mono-3.0.12.tar.bz2
cd mono-3.0.12/
./configure --prefix=/opt/mono/3.0/ --with-libgdiplus=installed --with-ikvm-native=no --with-moonlight=no --with-monotouch=no --with-monodroid=no --with-mobile=no --with-mcs-docs=no --with-x
configureの結果例。
mcs source: mcs Engine: GC: sgen and bundled Boehm GC with typed GC and parallel mark TLS: __thread SIGALTSTACK: yes Engine: Building and using the JIT oprofile: no BigArrays: no DTrace: no LLVM Back End: no (dynamically loaded: no) Libraries: .NET 2.0/3.5: yes .NET 4.0: yes .NET 4.5: yes MonoDroid: no MonoTouch: no JNI support: libgdiplus: assumed to be installed zlib: system zlib
ビルド、インストール
準備が整ったら、make、make installする。
make
sudo make install
参考までに、Core 2 Duo E6600を積んだマシンを使用してmakeに掛かった時間は以下のとおり。
$ time make real 27m6.562s user 21m31.461s sys 1m26.053s
動作確認
新しくMonoをインストールした場合
mono -Vでmonoが動作することを確認する。
$ mono -V Mono JIT compiler version 3.0.12 (tarball 2013年 6月 21日 金曜日 21:14:31 JST) Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com TLS: __thread SIGSEGV: altstack Notifications: epoll Architecture: x86 Disabled: none Misc: softdebug LLVM: supported, not enabled. GC: Included Boehm (with typed GC and Parallel Mark)
既に別のバージョンのMonoが存在する環境にインストールした場合
新しく/opt/monoにインストールしたMonoを参照できるように、環境変数を設定するスクリプトを用意しておく。 参考: Parallel Mono Environments - Mono
#!/bin/bash
MONO_PREFIX=/opt/mono/3.0
export DYLD_LIBRARY_PATH=$MONO_PREFIX/lib:$DYLD_LIBRARY_PATH
export LD_LIBRARY_PATH=$MONO_PREFIX/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=$MONO_PREFIX/include
export ACLOCAL_PATH=$MONO_PREFIX/share/aclocal
export PKG_CONFIG_PATH=$MONO_PREFIX/lib/pkgconfig
PATH=$MONO_PREFIX/bin:$PATH
まずmono -Vで先にインストールされていたmonoが動作することを確認する。
$ which mono /usr/bin/mono $ mono -V Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-1ubuntu2.2) Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com TLS: __thread SIGSEGV: altstack Notifications: epoll Architecture: x86 Disabled: none Misc: softdebug LLVM: supported, not enabled. GC: Included Boehm (with typed GC and Parallel Mark)
続いて、先ほど用意したスクリプトを読み込んだあとでmono -Vを実行し、新しくインストールしたmonoが動作することを確認する。
$ source mono-3.0-env $ which mono /opt/mono/3.0/bin/mono $ mono -V Mono JIT compiler version 3.0.12 (tarball 2013年 6月 21日 金曜日 21:14:31 JST) Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com TLS: __thread SIGSEGV: altstack Notifications: epoll Architecture: x86 Disabled: none Misc: softdebug LLVM: supported, not enabled. GC: Included Boehm (with typed GC and Parallel Mark)
GAC
gacutil2 -lでアセンブリがGACに登録されていることを確認する。 GACのパスを明示的に指定する場合は-rootオプションで指定する(例えばgacutil2 -l -root /opt/mono/3.0/lib/など)。
$ gacutil2 -l The following assemblies are installed into the GAC: : System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.ComponentModel.Composition, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.ComponentModel.DataAnnotations, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Configuration.Install, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 :
mcs, gmcs, dmcs
mcs(C#コンパイラ)の動作を確認する。
using System;
class Test {
static void Main()
{
Console.WriteLine(Environment.Version);
}
}
$ mcs test.cs && mono test.exe 4.0.30319.17020 $ mcs -sdk:2 test.cs && mono test.exe 2.0.50727.1433 $ mcs -sdk:4 test.cs && mono test.exe 4.0.30319.17020 $ mcs -sdk:4.5 test.cs && mono test.exe 4.0.30319.17020
gmcs, dmcsも使うことが出来る。 gmcsは-sdk:2, dmcsは-sdk:4を付けてmcsを呼び出すのと同じ。
$ gmcs test.cs && mono test.exe 2.0.50727.1433 $ dmcs test.cs && mono test.exe 4.0.30319.17020
csharp(C#シェル)
csharpシェルが動作するか確認する。
$ csharp -e 'Environment.Version;' 4.0.30319.17020 $ csharp -e 'Environment.OSVersion;' Unix 3.2.0.32 $ csharp Mono C# Shell, type "help;" for help Enter statements below. csharp> 1 + 2 3 csharp> quit;