Thursday, February 25, 2016

How to compile mono and run a C# code on CentOS

Goal:

How to compile mono from source code and use mono to build a C# code on CentOS.

Env:

CentOS 6.5

Solution:

1. Checkout Mono source code from github

Refer to http://www.mono-project.com/docs/compiling-mono/linux/
git clone git://github.com/mono/mono.git

2. Switch to a branch

cd mono
git checkout mono-4.3.2-branch

3. Build mono from source

./autogen.sh --prefix=/usr/local
make get-monolite-latest
make
make install

4. Create a sample C# code

# cat test.cs
using System;
class ExampleClass
{
    static void Main()
    {
        Console.WriteLine("Hello, world!");
    }
}

5. Compile C# code using mono and execute it.

mcs test.cs
mono test.exe

2 comments:

  1. bash: ./autogen.sh: No such file or directory
    giving this error in centos 6

    ReplyDelete

Popular Posts