I was recently bequeathed a somewhat older, PowerPC-based G5 Mac running OS X 10.4.11. Being a .Net programmer, one of the first things I thought of, spurred by memories of a code magazine article from the May-June 2009 issue, was to install Mono, the project that allows .Net code to run of various flavors of *nix, including OS X, on my "new" Mac. The idea of being able to run my .Net apps on Macs was very exciting; I’ve known about the Mono project since its inception, but never had a Mac of my own with which to try it. I had also heard negative reports about its usability in its baby years; but have since heard that it is much-improved, and possibly a viable approach for commercial apps. So, I resolved to try it on my newly-received Mac…
Following is a description of the ensuing adventure, with the hopes of making it easier for those who wish to follow in my footsteps.
Downloading the Mono Framework
First things first; I needed to download and install Mono on my Mac. The aforementioned CoDe Magazine article steered me to the main download page; following the OS X-specific link brought me to the Mono-on-OS X introduction page at http://www.mono-project.com/Mono:OSX, which is very helpful, and includes a link to the Mono download page at http://www.go-mono.com/mono-downloads/download.html. Clicking the "Mac OS X" link near the right side caused a panel to show up with download links, under the bullet point "Mono 2.6 Framework" (current as I’m writing this), for the various flavors of OS X processor. Choose according to which processor is in your Mac, either Intel or PowerPC. If you are a relative newcomer to Macs, you can determine which processor you have by clicking the blue Apple icon in the very-top-left-hand corner of your screen (on the system menu), choosing About This Mac from the menu, and reading the text after Processor in the dialog that pops up.
Now that you know which processor you are running on, click the appropriate link, either Intel or PowerPC. The third option, "Universal", gives you a "Universal Binary", which is a binary that will run on both PowerPC- and Intel-based Macs– but as usual with such things, will run much more slowly. Do yourself a favor and get the download specific to your processor. I recommend you do what I did, and also grab the "CSDK" linked next to your processor; though I haven’t gotten that far yet myself, the download page indicates that this package will allow you to bundle the Mono framework with your application, an ability with obvious appeal to those intending to distribute their software to end users who may not already have Mono on their Macs.
Now you get to wait while the rather large Mono Framework package, and the much-smaller CSDK package, download. You will likely receive an are-you-sure-you-wanna-do-this warning for each package, indicating that you are downloading a program. Simply OK each download.
You will eventually wind up with a .dmg file for each package, presumably on your Desktop, unless you’ve told your browser to download it elsewhere, in which case you should know where the files went! For simplicity’s sake, I’m going to assume you downloaded the files to your Desktop from here on. If not, simply make the mental adjustment from "Desktop" to "that-folder-where-I-set-my-browser-to-dump-downloaded-files" whenever I say "Desktop".
Installing the Mono Framework
We’re going to install the Mono Framework first. Find the .dmg file named MonoFramework-x.x.x_x.macos10.novell.[your-processor-type].dmg, where x.x.x_x represents the version you downloaded –mine was 2.6.1, which was the current version at the time of this writing, and showed up as 2.6.1_1 — and [your-processor-type] will be either ppc, for PowerPC, or x86 for Intel. Double-clicking the .dmg file leaves you with the standard Mac "removable-drive-looking-thingy" icon on your Desktop. Double-clicking that opens a folder with a .pkg file and the docs file, Notes.rtf, which you should open and read. Then, double-click the .pkg file, which will be named with the same MonoFramework-x.x.x_x.macos10.novell.[your-processor-type].pkg format.
The Mono Framework installer will open. Since you are, presumably, an experienced .Net programmer if you’re reading this, I don’t need to guide you step-by-step through a bog-standard installer. There are no surprises here.
Verifying the Framework has installed properly
Next, I wanted to verify that Mono was up and running. On the previously linked Mono-on-OS X Introduction Page, there are instructions for using Vi to do this; but I am not a Vi user, and immediately ran into issues. So, I poked around the site a little, and found the following link: Mono Basics. This page had some simple code, and directions on how to compile & run it. As per the instructions, create and save a simple console application in a text editor, such as the following (go ahead, copy and paste it. I won’t mind! 🙂
public class HelloWorld
static public void main()
console.WriteLine("Hello World, Mono is running.");
Of course, you need to make sure that whichever editor you use saves it as plain-old ASCII text, and doesn’t add on an extension. I used OS X’s built-in editor, TextEdit; if you do, you’ll need to go into the Format menu and click Make Plain Text before you save the file. Save it as HelloWorld.cs.
Once you’ve got the file saved, open Terminal, and use the CD command to move to the directory where you saved the HelloWorld.cs file. Build and run the program with these commands in Terminal, hitting <return> after each line (don’t enter the $ symbols, obviously!):
$ gmcs HelloWorld.cs
$ mono HelloWorld.exe
You should see the following result in Terminal:
Hello World, Mono is running.
Ta Da! You have installed Mono successfully! But we’re not done yet…
Unfortunately, though, this post is getting really long, so we actually are done, at least for today.
Continued in Part Two…