This tutorial covers the introduction, installation, and configuration of DarwinPorts, a software package manager for the Tiger 10.4 version of Mac OS X, and a requisite tool for nearly all subsequent Server Codex tutorials.
While most Mac software is installed simply by dragging the application to your Applications folder, server software and development tools are often implemented as command-line interface (CLI) programs that lack a graphical user interface (GUI) and thus can be considerably trickier to install. Aside from the few GUI-wrapped CLI programs that can simply be dragged to the Applications folder, there are three main methods for installing GUI-less software:
* Source tarballs (that must be manually downloaded and compiled)
* Port managers (e.g., DarwinPorts, Fink)
* Installer packages (i.e., .pkg files)
There is often a trade-off between flexibility and ease of installation, with source distributions providing the most configuration options — and the most cumbersome installation. Installer packages, on the other hand, can just be double-clicked and installed via Apple’s standard Installer application, but the administrator will have zero control over compile-time options or where the software is installed. Keeping software and dependencies up-to-date can also be a major challenge when relying on either source distributions or installer packages.
Port managers such as DarwinPorts and Fink were created to simplify the process of installing and managing software packages that would otherwise be a pain to maintain.
This tutorial is going to focus on DarwinPorts, for reasons already best explained elsewhere. If you would rather go with Fink, there are both basic and advanced tutorials available. (Please keep in mind, however, that future Server Codex tutorials will rely on DarwinPorts — not Fink — so it’s probably best to stick with the former.)
The following steps were performed on a fresh install of Mac OS X 10.4.5 Tiger (client version) and assume the user has administrative privileges. The provided terminal commands assume the user is using the Bash shell, which has been the default in Mac OS X for quite some time. While these instructions should work just fine on 10.3, an older Panther-specific install guide is also available from MacDevCenter.
Step 1: Installing the Xcode Developer Tools
Rob Griffiths of Mac OS X Hints fame put together a great tutorial on installing Xcode, so thankfully we won’t have to repeat those instructions here. If taking Rob’s advice to perform a space-saving custom install, ensure that as a bare minimum the following packages are included:
* Developer Tools Software
* gcc 4.0
* gcc 3.3
* Mac OS X SDK
* BSD SDK
* X11 SDK
* Mac OS X 10.4 (Universal) SDK
Step 2: Downloading and Installing DarwinPorts
Download DarwinPorts from the Get DarwinPorts page and save the .dmg archive to your Home folder.
Double-click the .dmg file and then the .pkg file within (unless you’re running Safari, which takes care of these steps for you). Choose a disk to install the DarwinPorts binary and supporting files.
That’s all there is to it. In case you’re curious, as part of the install process, your
~/.profile is modified (or created if it did not exist) to include the following lines:
# Your previous .profile (if any) is saved as .profile.dpsaved
# Setting the path for DarwinPorts
Because the new DarwinPorts paths are now listed before the existing standard OS X bin paths, software you install via DarwinPorts will take precedence over older versions that may have already been included as a part of Mac OS X. We will examine why this is useful in the next section.
Step 3: Installing Software
It’s best to make make sure the DarwinPorts system is fully up-to-date before installing new software. Using iTerm, Apple’s Terminal.app, or your preferred terminal, open up a new terminal session and enter:
$ sudo port selfupdate
Since we just installed DarwinPorts, it’s unlikely that DarwinPorts itself will be upgraded to a newer version. However, the information about the latest software package versions (contained in “portfiles”) is also updated with this command. Now we are ready to begin installing new software!
For our first installation, we will begin with the latest version of Ruby, an increasingly popular software development language. Before we install it, however, we’ll find out a little bit about the version of Ruby that Apple ships with Mac OS X.
$ which ruby
The output of this command should be /usr/bin/ruby, which tells us the location of the currently-active, Apple-supplied instance of Ruby. If we want to find out the version of Ruby that is currently active, the following command will tell us:
$ ruby --version
The output is:
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]
There are a few problems with Ruby 1.8.2 as installed by Tiger. While there are ways of fixing these problems, an easier method is simply to use DarwinPorts to install a separate instance of Ruby. Not only will this provide a fully-working Ruby while leaving the default Tiger version alone, we also get to use the latest version of Ruby without having to wait until Mac OS X 10.5 is released.
Now we’ll begin installing Ruby. Depending on the speed of your computer, the compilation of Ruby and its dependencies may take a considerable amount of time, so don’t be alarmed if an hour goes by and the installation still isn’t complete. Once the command below is entered and followed by an administrative password, DarwinPorts will begin by downloading, compiling, and installing the dependencies that Ruby needs in order to function (libiconv, zlib, openssl, and readline).
$ sudo port install ruby
After the required dependencies have been installed, DarwinPorts will automatically begin downloading, compiling, and installing Ruby itself. Once that process is complete, open a new terminal session and enter the following commands, which should be followed by the output below.
$ which ruby
$ ruby --version
ruby 1.8.4 (2005-12-24) [powerpc-darwin8.4.0]
The above commands indicate that our fresh DarwinPorts-managed version of Ruby is now active and ready for use. Congrats — you’ve installed your first DarwinPort!
Other useful commands
$ sudo port sync
This updates the local portfile descriptions, making sure that new installations as well as software upgrades always reflect the latest version. It’s a good idea to do this before using commands such as
$ port search ruby
This example command will search and display the list of available ports that contain the word “ruby” in the title.
$ port info ruby
This will output the version number, port description, available variants (if any), dependencies, and other useful information about the queried port name.
$ port variants ruby
If the only information we want is a list of any variants that may exist for a given port, this command will provide it.
$ port deps ruby
Similar to the above command, if the only information we want is a list of any dependencies that may exist for a given port, this command will provide it.
$ port installed
This command will show a list of all installed ports and their respective versions, both active and inactive. When you upgrade a port, DarwinPorts does not delete the previous version, but instead simply marks the new version as “active.” This is useful if you find that the new version isn’t working, as you can simply revert to the previous version by marking it as active.
$ sudo port deactivate ruby @1.8.4_1
As you might have guessed, this will deactivate the listed port version.
$ sudo port activate ruby @1.8.4_1
If we decide we want to re-activate an inactive port, this command will make the provided port active again.
$ port location ruby
This command, which will return an error if the queried port name is not installed, will output the location of the respective active port on your filesystem, which in this example is:
$ port contents ruby
This command, which will also return an error if the queried port name is not installed, will output the location of all the files installed by the respective active port.
$ port outdated
Predictably, this command will display a list of ports that have newer versions available than the versions installed. On the left are the version numbers installed, and on the right are the most recent version numbers available.
$ sudo port upgrade ruby
If we run the port outdated command and find that there is a new version of a particular port available, we can use the upgrade command to install and activate the new version.
$ sudo port -u upgrade ruby
Passing the -u flag will uninstall any and all previous versions of the specified port that may be installed, instead of leaving them inactive but still installed on the machine. If you know that you won’t need to revert to a previous version of a port, using this command will preserve disk space by removing inactive ports.
$ sudo port uninstall ruby @1.8.4_1
This command will uninstall the specified port. If you only have one version installed, the version number parameter can be omitted.
The above is meant to be a handy list of the most frequently used commands. Additional information on
port commands is available from the relevant DarwinPorts documentation topic.
Extra Credit: Port Authority
If you prefer to use a GUI application instead of the command line to install and manage your DarwinPorts, the folks at WordTech Software were kind enough to provide us with the free, open-source Port Authority application. Once the application has been downloaded and installed, a list of available (not yet installed) ports appears in the top pane, with a list of installed ports below.
If for some reason you find you need to uninstall DarwinPorts, the following command should do the trick:
$ sudo rm -rf /opt/local /Applications/DarwinPorts /Library/Tcl/darwinports1.0 /Library/StartupItems/DarwinPortsStartup
You now have all the tools at your disposal to install and maintain a vast number of useful software packages. Stay tuned for more detailed tutorials in the weeks ahead!