Open Source Options for Mac OS X
Volume Number: 23 (2007)
Issue Number: 06
Column Tag: Open Source
Open Source Options
for Mac OS X
How to leverage open source applications in Mac OS X 10.4
By Mary Norbury
With all the hype about virtualization possibilities on the Mac, it's easy to forget that Mac OS X has been offering open source software users an efficient and powerful environment to run UNIX-based applications for over four years. The UNIX foundation of Mac OS X enables the user to explore a richer environment on a single machine than previously possible without using multiple hardware and software configurations. The exciting future of virtualization aside, this article attempts to re-acquaint or possibly introduce the reader to the world of open source software implementation on Mac OS X.
Terminal.app was quickly adopted by many experienced UNIX and Linux users and enabled command line junkies the means to interact with their Macs on a more powerful level. There are many shell-based UNIX open source apps that can be run directly from the Terminal without code tweaking or with minor changes... but what of the thousands of other GUI UNIX open source apps that rely on a different graphical user interface to draw correctly on your Mac desktop? Enter the X Window System.
X Window System and X11
The X Window System is a network and display protocol that includes the basic tools for building a graphical user interface. X11 allows UNIX-based GUI applications (as opposed to terminal or command line apps) to draw to the screen. The X Window System is actually a graphical interface server that communicates with client applications. The client applications can be run on the same machine as the X11 server or it can be run on other machines (hence the "network" aspect of the X protocol). The current X Window System version is 11, released in 1987, hence the X11 nomenclature. The current release is X11R6 or simply, R6. X does not define a specific application user interface (menu and title bars, menus, desktops, etc.) and is not vendor-controlled (ahem...MS and Apple); therefore, window managers (Enlightenment, Oroborus, Window Maker) and desktop environments (Gnome, KDE) detail these specifics. Hence, there is a wide disparity of functionality and visual variety to be found.
Pre-OS X, Apple developed MacX for OS 7, OS 8, and OS 9 for internal use. Apple introduced the first XFree86 based X server - the XDarwin release for Mac OS X 10.0 - in 2000. Extremely limited in functionality, it was nevertheless a major step toward unlocking the power of UNIX on the Mac. At MacWorld in January of 2003, Apple quietly announced the public beta release of X11 for Mac OS X and instantly aroused the interest of the UNIX and Linux community. The Mac as a viable alternative for running UNIX-based software was an exciting reality.
X11 for Mac OS X is Apple's version of the X Window System, based on the open source XFree86 project (http://www.xfree86.org/). X11 for Mac OS X consists of the X11 window server, libraries, utilities (xterm, xhost, xeyes), the Quartz rootless window manager, which offers significant graphics enhancement to apps that have high display requirements (model manipulation, manual rotation/translation, molecular dynamics simulations), and hardware OpenGL acceleration. Open source command line apps can easily be adapted to Mac OS X (via Terminal.app) but the open source GUI apps were developed for a windowing system significantly different from Aqua. X11 for Mac OS X allows open source applications to run without code modifications and in their native windowing environment.
There are other X Window Systems for Mac OS X: OroborOSX, BlackBox, Tenon's not free (read: commercial) Xtools, as well as others.
There are many reasons to explore X11 but one of the most compelling is the ability to use the thousands of open source, X11 based applications that have been available to UNIX and Linux users for many years. Breaking free of proprietary, restrictively licensed, exorbitantly priced software is never a bad thing. The most commonly used examples of alternatives to mainstream software are The GIMP (GNU Image Manipulation Program, http://www.gimp.org), an image editing application akin to PhotoShop and OpenOffice (http://www.openoffice.org), a full productivity application suite similar to MS Office. Both of these venerable application examples are well documented with tutorials, rapid bug-fix releases, development updates, and user wiki's, mailing lists, and bug reports. There are many other open source apps that fall all over the map from simple text apps to IM and email apps to iPod and DVD ripping apps to video playback to macromolecular crystallography to numerical analysis software...ad infinitum. I'll attempt to include a list of resources at the end of this article to whet the appetite and propel the reader in the correct direction.
Install X11
The first step is to install Apple's X11.app. Find your installation discs that came with your Mac, insert the first disc, locate the Optional Installs.mpkg and follow the prompts to install X11 (Figure 1).
Figure 1. Optional Installs.mpkg
You'll need to expand the Applications drop down to find X11 (Figure 2).
Figure 2. Expand Applications to find X11
Alternatively, you can launch X11User.pkg in /System/Installation/Packages on the disc. After a successful installation, you'll find the X11 server (X11.app) in /Applications/Utilities. The current 1.1.3 release version of X11.app corresponds to the XFree86 4.4.0 version. Also installed, besides /Applications/Utilities/X11.app, are the /usr/X11R6/include directory (header files that Fink needs to find are put here) and /usr/bin/open-x11 which is a script you can call to launch X applications from Terminal.
The next step is to install Xcode Tools and, in particular, the X11 SDK (you'll need the X11 SDK in order to build your own binaries from source code). You can get these from the Xcode Tools directory on the same install disc using XcodeTools.mpkg (see Figure 1), but I highly recommend that
you go to the Apple Developer Connection site (http://developer.apple.com/tools/xcode/) and download the latest public version there (2.4.1, as of this article). If you haven't installed the Xcode Tools yet, do a custom install and select everything. Along with the X11 SDK, you'll also need the gcc 4.0 compiler (which translates source code into an executable program). If you aren't sure what you have, pop in your first install disc or download the latest version from ADC, expand the Software Development Kits drop down to find missing/outdated components and upgrade (X11 SDK is selected in Figure 3).
Figure 3. X11.SDK Installation
Go to /Applications/Utilities and launch X11.app. You'll see the default xterm window (Figure 4).
Figure 4. Default xterm Window in X11.app
You can launch X11 through /Applications/Utilities or by opening an X11 application like GIMP or OpenOffice. For now, type exit at the prompt and then File - Quit to exit X11.
Fink
The Fink project was created in December 2000 to port UNIX software to Mac OS X and facilitate installation. Fink is based on Debian's package management tools (dpkg, dselect, apt-get) and the .deb binary package format but is configured for OS X.
Now we're ready to install Fink. Fink's Quick Start Downloads Page has excellent instructions on how to install Fink (http://www.finkproject.org/download/index.php?phpLang=en). Briefly, choose between the PowerPC Binary Installer and the Intel Binary Installer. The following assumes you have an Intel machine:
Download the Fink-0.8.1-Intel-Installer.dmg
Mount the Fink-0.8.1-Intel-Installer.dmg disk image and then launch the Fink 0.8.1-Intel Installer.pkg
You'll be prompted to allow the installer to edit shell configuration files and the installer will complete (Figure 5).
Figure 5. Fink shell Configuration
Fink installs to /sw to avoid conflicting with other packaging systems. Executables are installed into /sw/bin and config files end up in /sw/etc.
Create a new folder in /Applications and, before unmounting the Fink-0.8.1-Intel-Installer disk image on your desktop, drag the contents to your new folder in /Applications. FinkCommander.app, documentation, an FAQ directory, and a pathsetup.app (for other system users to run under their own account before using Fink) are included in this directory.
Open Terminal.app (/Applications/Utilities) and type:
fink scanpackages; fink index
You'll be prompted for your password. You'll get output as the process completes (Figure 6).
Figure 6. fink scanpackages; fink index Output
Alternatively, go to your newly created Fink folder and launch FinkCommander. Go to Source in the menu bar and select Scanpackages (Figure 7).
Figure 7. Scanpackages Using FinkCommander
Again, you'll be asked to authenticate. When that has completed, go to Source in the menu bar and select Utilities - Index. In both cases, you'll get output in the lower pane of the window.
Update the Fink package. There are several methods available to updating Fink:
Use FinkCommander.app to update Fink from binaries.
Binary - Update descriptions
Select the Fink package.
Binary - Install
Use FinkCommander.app to update Fink from source.
Source - Selfupdate
Tools - Interact with Fink...
Make sure Accept default response is selected, and click Submit.
Fink and other base packages will be built and run automatically.
Use apt-get to install from binaries.
Open a Terminal.app window and type:
TBoot:~ norburym$ sudo apt-get update; sudo apt-get install fink
You can also use dselect as a front end to apt-get. dselect is a ported Debian tool that allows for browsing and selecting packages.
Use Fink to install from source code.
To update Fink run:
TBoot:~ norburym$ fink selfupdate
When prompted, select option (1), rsync. This will automatically update the Fink package.
Optional But Recommended Step: Configure for "unstable" packages.
Some packages are considered "unstable" because they haven't been fully tested. These packages are often only available as source and will need to be compiled. Make a few changes to Fink to allow for unstable packages.
If you use Fink from a shell: open Terminal.app and type:
$ sudo pico /sw/etc/fink.conf
Enter your password when prompted. Add unstable/main and unstable/crypto to the Trees: line (Figure 8).
Figure 8. Edit fink.conf from a shell
Save and exit pico.
Finally, type:
fink selfupdate; fink index
If you use FinkCommander.app, open the GUI app, go to Preferences in the menu bar, select the Fink tab and select the checkboxes for Use unstable packages and Use unstable cryptography packages (Figure 9).
Figure 9. Edit fink.conf Using FinkCommander
Click OK. Authenticate when prompted.
Install other packages.
Use FinkCommander to install other packages.
To install from binaries, select the package, and use Binary - Install.
To install from source, select the package, and use Source - Install.
Use apt-get to install other packages (apt is Debian's "advanced package tool").
Use sudo apt-get install packagename
For example, sudo apt-get install gimp to install the Gimp.
Note, however, that not all Fink packages are in binary form.
Install other packages from source.
Use sudo fink install packagename to fetch and compile from source code.
For example, to install the Gimp, run sudo fink install gimp
dselect is also a package tool option to browse and select available packages but it has known issues with Mac OS X Terminal so we'll skip it. More information can be found at http://finkproject.org, in the User's Guide.
So how do you find an application to download via Fink? You can use the Fink Package Database (http://pdb.finkproject.org/pdb/index.php?phpLang=en), which offers two methods of finding a package: Search or Browse (the complete list or by archive section). As of April 25th, 7802 packages were available (including "unstable" versions vs. 1731 stable packages). For example, if you click on the games link, you'll see 212 packages listed. You can read a brief description of a package and then click on the link to get more detailed information about the package.
In my example, I chose a version of 3D Space Invaders with the package called xinvaders3D. To find this via a shell, type " apt-cache search space invaders". Note that I didn't have to know the exact name of the game. I wanted to search the Fink database for a space invaders game and it returned two results: one for a basic space invaders game and one for the 3D game:
TBoot:~ norburym$ apt-cache search space invaders
xinvaders - Space Invaders clone for X
xinvaders3d - 3D Space Invaders Game
TBoot:~ norburym$
Use this command to get more information about the package you are interested in: fink describe packagename (for our example, fink describe xinvaders3d).
To download the 3D game package in a shell, type:
sudo fink install xinvaders3d
Enter your password when prompted. You'll get output like this (Figure 10).
Figure 10. sudo fink install xinvaders3d
You could have also used apt-get to download the package:
TBoot:~ norburym$ sudo apt-get install xinvaders3d
FinkCommander
You can use FinkCommander to find and download the same package. Open FinkCommander.app and in the search field at the top right corner of the window, click on the drop down arrow next to the magnifying glass and select Description. This selects the field you want to search on. Note that the table is still sorting by the Name column. You are simply selecting to search the Description field. In this case, type space invaders and hit return (Figure 11).
Figure 11. Search for Packages in FinkCommander
Note that the Latest column indicates latest source code while the Binary column indicates the latest binary distribution. Sometimes, the source code is more up to date than the binary distribution. In this case, they are both the same versions. The xinvaders game in the line above it shows that the latest source code is more up to date than the binary version.
Select the xinvaders3d line, select Binary from the menu bar and choose Install from the pop down menu. Authenticate. You'll get the following output (Figure 12).
Figure 12. Using FinkCommander to Install Packages
Launch 3D Space Invaders
OK, so now we have our 3D Space Invaders game. How do we run it?
Since our game has been downloaded by default to /sw/bin (all executables), open X11.app and, in xterm, run: /sw/bin/xinv3d (Figure 13).
Figure 13. Launch 3D Space Invaders in X11
The game will load (Figure 14).
Figure 14. 3D Space Invaders in X11
Odds & Ends
Get a list of packages installed on your system by using this command in a shell: dpgk -l (Figure 15).
Figure 15. Installed Packages
or use the fink list -i command. Uninstall a package via apt-get: sudo apt-get remove packagename or via Fink: sudo fink remove packagename.
MacPorts
An alternative to Fink is MacPorts (previously DarwinPorts, started in 2002), based on the FreeBSD ports system. MacPorts installs by default into /opt/local so that, like Fink, system files in /usr or /usr/local won't be affected and MacPorts files and packages can be safely deleted simply by removing the /opt/local directory.
MacPorts can be found at: http://www.macports.org/, hosted by Mac OS Forge (http://www.macosforge.org/). The current version is 1.4.0 and can be downloaded at: http://svn.macosforge.org/repository/macports/downloads/MacPorts-1.4.0/ or http://svn.macosforge.org/repository/macports/downloads/. There are various flavors to be found here; choose either the latest .dmg or .tar.gz version. In our first example, we'll download the MacPorts-1.4.0-10.4.dmg file.
You can test your install by typing port at a shell prompt, which will return the MacPorts version number you installed (1.430, in this case) and put you in interactive mode. Type quit to exit. Next step is to send MacPorts the command: sudo port selfupdate, which will allow MacPorts to update itself, if necessary.
The alternative method for installing MacPorts is to download and install from source. From the site (http://svn.macosforge.org/repository/macports/downloads/MacPorts-1.4.0/), choose MacPorts-1.4.0.tar.gz (the .tar extension indicates that multiple files have been combined into a single file and the .gz extension indicates the archive has been compressed). We'll need to uncompress first, by typing "gunzip MacPorts-1.4.0.tar.gz", which will leave us with the archived files in the form of MacPorts-1.4.0.tar and then we'll open the archive using the command: tar xvf MacPorts-1.4.0.tar where the xvf functions stand for: x=untar (extract files from an archive), v=verbose/list files processed, f=file. Alternatively, you can combine the two commands into one with these options: tar xzf MacPorts-1.4.0.tar.gz where x=untar/extract files, z=uncompress using gzip, f=file. The default location for the files will be a new MacPorts directory in your home directory. To place the MacPorts installation in /opt/local, you'll need to build the source. Change to the MacPorts directory and run the following commands:
$ cd MacPorts-1.4.0
$ ./configure
$ make
$ sudo make install
Or
You can run the entire set of commands like this:
$ cd MacPorts-1.4.0
$ ./configure && make && sudo make install
You'll be prompted for your password before the build competes so watch for it. When done, you'll see a long output and be left at the command prompt (Figure 16).
Figure 16. Build MacPorts from source
Before you run the port update, you'll need to make sure that /opt/local/bin is in your path environment variable or your bash shell won't be able to find the MacPorts executables. To test this, just type "port".. You'll get this error:
$ port
-bash: port: command not found
To set the environment variable for your bash shell, add the following to your ~/.profile: export PATH=/opt/local/bin:$PATH (Figure 17).
Figure 17. Set environment variable in bash for MacPorts
If you have installed Fink using the directions above, you'll also see the Fink environment variable:
test -r /sw/bin/init.sh && . /sw/bin/init.sh
as in Figure 17. Fink and MacPorts can co-exist so don't worry. Save and exit. You'll need to quit your Terminal session and restart it. Now, type port at the command line and you'll see the MacPorts version which is MacPorts 1.400 in this example. Run port sync to download the Portfiles (port description files) and when it's done (no verbose output in the shell; it will return you to the command prompt when it's complete), run sudo port selfupdate to update the MacPorts base and the Portfiles (Figure 18) to the current version 1.430.
Figure 18. port sync and port selfupdate
To find software packages to download, you can go to the MacPorts Browse Source Link (http://trac.macosforge.org/projects/macports/browser/trunk/dports) or you can search from within the Terminal.app by using the port search command. For example, let's look for a popular MahJong UNIX-based game:
TBoot:~ norburym$ port search mahjong
We get a result:
xmahjongg games/xmahjongg 3.6.1 X graphical mahjongg solitaire game
You can get more information on the xmahjongg package by using the port info xmahjongg command:
TBoot:~ norburym$ port info xmahjongg
Download the package by typing the following:
TBoot:~ norburym$ sudo port install xmahjongg
Authenticate and wait. When the package has been installed, you will see something similar to this (Figure 19).
Figure 19. sudo port install xmahjongg
Verify your installation by using the port installed command. You should see the xmahjongg package listed alphabetically.
More Odds & Ends
A number of build files will be left behind in the process of installation. To clean these up, use the sudo port clean packagename command (ex. sudo port clean xmahjongg).
To uninstall any package, use the sudo port uninstall packagename (ex. sudo port uninstall xmahjongg).
PortAuthority
PortAuthority is the GUI front end for MacPorts. I have to mention that this application is shareware and not a free app.
The source can be downloaded from SourceForge.net (http://sourceforge.net/projects/dpgui). To install from the command line, move the .tar file to your home directory, open the .tar file with:
TBoot:~ norburym$ tar xvf port_authority_source.tar
To complete the install, read the building_port_authority.txt document; there are a number of external dependencies that must be installed and this text file lists each one including where to download the external packages and how to install them.
Or far more simply, the .dmg file can be found at Apple's UNIX & Open Source Downloads page (http://www.apple.com/downloads/macosx/unix_open_source/). Move the PortAuthority.app to your Applications folder and launch it. You'll see a reminder that your copy is a 30-day demo version. Click your choice to buy or try and the PortAuthority preferences will appear. Save the default. You can search for a particular port and download it using the package icon in the toolbar. Let's look for one of my favorite time wasters...er, brain stimulators, the solitaire game MahJong. Keep it simple: put in the search term, mah. PortAuthority will display the xmahjongg package in the upper pane. Highlight it and click the Install a MacPorts port button in the task bar or go to Installations in the menu bar and select Install a Port from the drop down options. You'll be asked to authenticate and the process will show in the lower right pane (Figure 20).
Figure 20. PortAuthority
Launch MahJong
Since our game has been downloaded by default to /opt/local/bin (all executables), open X11.app and, in xterm, run: /opt/local/bin/xmahjongg (Figure 21). That's it!
Figure 21. MahJong in X11, Showing xterm
FinkCommander vs. PortAuthority
FinkCommander is polished, intuitive, efficient...and, um, free. PortAuthority is none of these. While PortAuthority downloaded most of the packages I selected, the search field would not allow for selecting the column I wanted to search on (clicking the down arrow did nothing), the interface is at times alarmingly "classic" (Figure 22), I had to quit the app and relaunch it immediately after install because it gave password errors, it takes a bit too long to load available packages, and it is not free.
Figure 22. Waiting...
However, I do use both Fink and MacPorts and while I prefer to download from source and compile, sometimes it's just plain easier to use the GUI.
Conclusion
While installing applications via the "double-click-the-installer" method has its merits, there is a wealth of established open source applications in the wild that can be had for a minimum of effort. Besides the games sampler in the examples in this article, there are many productivity suites, graphics applications, web, database, multimedia players, podcasting, animation, and sound editing/recording apps that will most likely fit any situation you require. Once you become familiar with the installation options described here, the world of open source is available to you.
Some Helpful References
MacForge: Mac open source projects
http://www.macforge.net/
XFree86 Project Home
http://www.xfree86.org/
Apple's X11 Home
http://www.apple.com/macosx/features/x11/
Fink Project Home
http://finkproject.org/
FinkCommander Home
http://finkcommander.sourceforge.net/
MacPorts Home
http://www.macports.org/
PortAuthority Home:
http://www.codebykevin.com/portauthority.html
http://www.opensourcemac.org/