Installing Mono: Running .NET on Linux and Windows by Charlie Calvert

Abstract: This article present a basic description of how to install Mono on Linux or Windows, and how to get a simple CSharp program up and running on both platforms. The steps described here are current as of April 2004.
Copyright (c) 2004 by Charlie Calvert

This article gives a brief overview of the Mono project, and then describes how to install Mono on Windows and Linux. After describing the installation, I present a very simple Mono CSharp program that you should be able to compile and run on either Linux or Windows. Two other articles in this series describe how to get Mono ASP.NET files up and running on Linux and Windows, and how to get Mono Windows Forms applications running on Linux and Windows.

For Linux users, it is quite possible that you already have a version of Mono installed on your system. Type the command for running the Mono CSharp compiler to test if it is present: mcs. If that gets a valid response, then you probably have Mono installed already. However, Mono is a rapidly changing tool which is currently under heavy development. It is therefore worthwhile to get a fairly recent build so that you can track the current state of the project. The installation process described here explains how to get the most recent build. None of the Mono builds are rock solid all the way through, but there has been a remarkable amount of work done, and much of the code is of good quality.

Intro to Mono

I should give a little background before discussing how to get the experimental Windows.Forms code up and running. The Mono project is sponsored by Novell, and is designed to implement the .NET Development Framework standard in cross platform, open source code.

The main features of the Mono project are the implementations of ADO.NET, ASP.NET and the CSharp compiler. Unlike the Windows.Forms code, these sections of the project are relatively mature at this time.

The CSharp compiler, MCS, has reached the 1.0 mark, and is considered fully operational and ready for prime time. It is written entirely in C#, and is able to compile itself. It can also compile Mono, which currently consists of 1.7 million lines of CSharp code. You can download the source to the compiler and Mono itself at the Mono download web page.

Though not quite at 1.0, the mono ASP.NET code is quite mature. The ADO.NET project is huge, and hence has a bit further to go. At this time it provides access to the following databases: Firebird/Interbase, IBM DB2 Universal Database, MySQL, ODBC, OLE DB, Oracle, PostgreSQL, SQL Lite, Sybase, Microsoft SQL Server, and TDS Generic.

Windows Install

You can download Mono sources or binaries for either the Windows or Linux platforms, plus a number of UNIX platforms. The Windows install is forehead based, meaning that you can (almost) install it with only your forehead, and without using your hands. If you can click on an executable, you probably have the technical expertise necessary to perform the install.

After the install is complete, you will probably want to ensure that the Mono bin directory is on your path. If you can type mcs and get a valid response, then you know you have it installed and set up correctly. Near the end of this article you will find a simple example program that you can compile and run to test your install.

Linux Install

On Linux, the best way to get Mono is via Red Carpet, though you are also free to struggle with either the raw source, theRPM packages, or the CVS daily code available from the download site.

I want to emphasize that Red Carpet is by far the best way to get this complex install up and running correctly on your system. The second best system would probably be to get the source code either from cvs or the download site, and to build the source with the classic three step:

./configure
make
su -c "make install"

You can generally undo this kind of install with the following command:

su -c "make uninstall"

However, the best way to manage a complex deployment of this type is with RPM, since it will better handle conflicts, queries and uninstalls. The problem with RPM in this case, however, is that you are likely to encounter many conflicts between the various programs needed to install Mono and the code currently on your system. By using Red Carpet, you can still get the benefits of RPM, but get additional help automating the process of resolving version conflicts. In general, I think it is wise to use a tool like Red Carpet, or the RedHat Network, rather than taking too much personal responsibility for keeping your system up to date.

When using Red Carpet, turn to the Search page and choose the Mono channel, as shown in Figure 1. If necessary, conduct a search to find the channel. You will find a list of some 50 or 60 different pieces of software that need to be installed. In theory, you can just select them all, choose Mark for Installation, and then press the Run Now button.

Figure 1: On the Red Carpet search page you can select the Mono channel. Select files from the Mono channel, choose Mark for Installation at the bottom left, and press the Run Now button on the top left of the application.

If the Red Carpet install does not go smoothly, try selecting individual items and installing them one at a time, or two or three at a time. Red Carpet gives you enough feedback so that you know what a particular item depends upon. Just start drilling down into the depends list, looking for items that don't depend on anything else. Install them first, then slowly work your way backwards toward the top level items. It can be a bit time consuming, but in the end you should be able to get your system up to date.

Though it is not absolutely necessary for all the features of Mono, you really should get Wine installed. Wine is especially important if you are interested in Windows Forms.  A special Mono centered version of Wine is included on the Red Carpet Mono channel. The RPM based Red Carpet install should set everything up for you correctly. To test your Wine install, go to the Linux shell prompt and type notepad. If a copy of the Windows Notepad program appears, then you probably have things set up correctly.

If you are having problems, find the rpm install for the following utility: winesetuptk. I used winesetuptk-0-73.i586.rpm. Install winesetuptk using this command: rpm -Uhv winesetuptk-0-73.i586.rpm. After the install, run winesetuptk from the command line and let it step you through the process of setting up wine.


Figure 2: Use winesetuptk to automatically configure your Wine installation.

Testing Your Installation

After installing Mono, you will want to run a simple test to confirm that it is working. Use a text editor to enter the simple CSharp program shown in Listing 1.

Listing 1: Save this simple program as hello.cs.

using System;



namespace HelloNameSpace
{
public class Hello
{
static void Main(string[] args)
{
Console.WriteLine("What we think, we become.");
}
}
}

To compile the program on either Windows or Linux, type: mcs hello.cs. On Linux, the output should look something like this:

<[charlie@rohan hello]$ mcs hello.cs
Compilation succeeded
[charlie@rohan hello]$ ls -l
total 5
drwxrwxr-x 2 charlie charlie 1024 Apr 2 16:06 CVS
-rw-rw-r-- 1 charlie charlie 171 Apr 11 15:22 hello.cs
-rwxrwxr-x 1 charlie charlie 3072 Apr 11 15:25 hello.exe
[charlie@rohan hello]$/pre>

Note that the program is called hello.exe, not hello. I suppose this is to done emphasize the fact that it is different from most Linux applications. In particular, it needs the Mono runtime to run. To run the program, type: mono hello.exe. The output should look something like this:

[charlie@rohan hello]$ mono hello.exe
What we think, we become.
[charlie@rohan hello]$

On Windows, the process is nearly identical, but you cannot count on the fact that mcs.exe is on your path. As a result, you may need to change your path, type a long command line, or work inside the Mono install directory.

If you can get Mono installed, and compile the hello.cs program, then you at least have the basics of Mono setup on your system. The next step is to read my article and get some ASP.NET programs up and running. If you can get over that hurdle, then try for a Windows Forms program.

Summary

In this article you have learned how to install Mono on either Windows or Linux, and how to get a simple Mono CSharp program up and running. Mono has made remarkable progress in a relatively short period of time. However, it still has a way to go before it will be fully functional. I believe, however, that Mono would be a good thing for developers, as it would add to the list of powerful languages, such as Java and Python, that developers can use when they want to create cross platforms applications with a powerful, easy to use language. The great thing about languages like Java, Python or CSharp is that they are relatively easy to use. They also have a modern, sophisticated architecture that promotes good programming practices. C++ provides cross platform support, but it is difficult to obtain the same degree of productivity in C++ that you can get in languages such as CSharp, Java or Python.


Server Response from: BDN10A

 
© Copyright 2008 Embarcadero Technologies, Inc. All Rights Reserved. Contact Us   Site Map   Legal Notices   Privacy Policy   Report Software Piracy