Bootstrap software
From Wiki99
↑ Computers ↑
← prev: Introduction
next: TCP/IP Addressing →
Contents |
Ways of Obtaining the Software You Will Need
We will be discussing a variety of open source programs in these essays.
How do you get hold of them?
The possibilities include:
- The program comes pre-installed with MacOS X
-
The program can be installed using a special purpose installer some person wrote especially for that application
-
The Fink package management system
-
The Darwin Ports package management system
-
Obtaining the raw source code for the application and compiling it
For most people, the first situation, where Apple pre-installs the program, is the most desirable. For the most part (though, sadly, not always) the program will work and will be kept up-to-date through OS and security updates. The Apple version won't necessarily be the absolutely most recent version, but it is usually the most recent version that has been used widely and whose limitations are understood.
But we can't always rely on Apple (though it doesn't hurt, if you feel a certain piece of software is common enough that it should be part of the OS, to write up an Apple bug report requesting this). So then what?
It is tempting to assume that the next best alternative is a custom installer. These installers are generally pretty well written, and the people who write them try hard to follow the Apple way of doing things in terms of where in the file system they place auxiliary items like preference files and documentation. The only real problem with them is that each one is its own separate item, and tends to be updated sporadically.
In contrast, the two package management systems, Fink and Darwin Ports, try to be managers of all the additional software you install through them. This means that you can ask them which packages they have installed for you, or you can ask them to update all the packages they have installed. They both follow a consistent model for where they place files in the file system which is deliberately as separate as possible from where Apple places its files so that the two don't interfere. The idea is that changes to your Fink files, your Darwin Ports files, or your Apple files, should all have no effect on anyone else.
Fink comes from the Linux world, Darwin Ports comes from the BSD world. They are both run by volunteers who do their best, and for the most part do very well, but they both occasionally have their problems.
My preference is, wherever possible, to install something using Darwin Ports, the idea being that it's nicest if you have only a single place you have to go to whenever you want to update your programs. The convenience (and safety of installation) of Darwin Ports is very nice, but their is a price to be paid in that the installed programs are (deliberately) somewhat detached from the MacOS X world, and you will have to learn how to get the two to talk to each other. You'll see frequent example of this as we proceed through the essays.
If you are a novice, you might prefer to use a more mac friendly installer for various programs and only use Darwin Ports or Fink if you absolutely have to. In that case, you should generally so some sort of google search (for example "mysql macos x installer") for any piece of software you are interested in and, if that comes up empty, try Darwin Ports.
If Darwin Ports fails you, the next alternative is to try for a dedicated installer. If that's unsuccessful, you could try Fink, but life now bcomes messy when you have both Darwin Ports and Fink managing packages on your mac.
Trying to compile the raw source code is a rather specialized job that you probably shouldn't attempt unless you really know what you are doing.
Darwin Ports Basics
Darwin Ports operates by managing a database of programs it knows how to install. When you ask it to install a particular program, it consults that database to find a particular file, called a port file, that describes how to install that particular program. The port file generally describes
- what other programs or libraries the program of interest depends upon. (These programs or libraries will in turn be downloaded and installed before the rest of the installation of the program you care about.)
-
where to go on the internet to download the relevant source code for this package
-
how to compile and link the package
-
where in the file system to install the package (including perhaps any special things that have to be done to fully install the package; for example some package need some changes made to OS files to ensure that they are always launched when the system reboots
It is important to realize that something can go wrong at each of these steps. If you are familiar with UNIX and, in general, have the skills and patience to debug computer problems, you can usually figure out what has gone wrong.
As an example, a port file might try to download file zlib.1.2.2 from some URL, and fail. If you visit the web site specified by the URL, you might see a notice saying that zlib.1.2.2 has been made unavailable because it has a security flaw and you should use zlib.1.2.3. Scanning the port file, it should be pretty obvious the various places where you need to change 1.2.2 to 1.2.3 to make everything work.
Another possibility is that something may go wrong in the compile. If this is complicated, your only solution may be to report a bug to the Darwin Ports team and wait for them to fix it, but sometimes it is pretty obvious what the problem is, for example some minor change in how gcc 4.0 handles some obscure C++ syntax compared to how gcc 3.3 handled it, and you can just make the change and try to build again. (Of course, even if your change works, you should still report the problem, along with your fix, so that things are improved for the next person who downloads.)
XCode and Darwin Ports installation
To build any sort of code on your mac, the first step is to obtain XCode, which you can download from
Once that large download has completed, run the installer. Unless you have good reasons to do otherwise, just accept the default installation setup the installer gives you.
With XCode in place, you now need Darwin Ports.
Darwin Ports seems to have changed its URL quite a few times over the
past few years. Right now the two best URLs appear to be:
http://www.macports.org/
and
http://darwinports.com/
The macports.org site is, in some sense, the "official" site, and is the
location of the latest software release. However pretty much all it carries
is the initial installer software.
The darwinports.com site is somewhat misleading, advertising prominently
older versions of the installer software (though it does carry the newest
installer software if you look around more carefully). However the good thing
about it is that it hosts the catalog of all the available ports, which can
make it a whole lot easier to try to find a particular program. It also carries
basic how-to information.
You should go to the darwinports.com home page and read if anything new has changed from the procedure I give below, but right now the procedure is to first download the Darwin Ports program from the page
and run the installer.
Once the installer is finished, you need to change your $PATH variable to include reference to the Darwin Ports binaries. I assume you are using the default Apple bash shell setup. Use your favorite editor to open the file ~/.profile (if you don't have this file, create it). Add to this file the line
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
At this point the easiest thing to do to ensure everything works is to close the terminal window you were using and open a new terminal window that will read in the changed made to your ~/.profile file. You can type echo $PATH to ensure that your $PATH is correct.
At this point we are now ready to tell Darwin Ports to update itself and its database with any changes that have occurred since the file you downloaded was created. In a terminal window type
Installing some code using Darwin Ports
The selfupdate above is fairly typical of how you use Darwin Ports.
The command line tool you use is called port. If you are just asking
port for some information you can run it directly, but if you need
it to write to the filesystem you will have to run it as root, hence the
sudo.
If you are like me, you like to see lots of status information as a command
progresses so that know what is happening and if anything goes wrong. The
-d (debug) option prints out progress information. Often, however,
-d prints out too much information, obscuring what matters, so
the -v (verbose) flag is more useful.
After the -d and similar flags, there is an actual command that
tells port what it should do, in this case selfupdate.
Useful port commands are
| port contents xxx | (what will be installed by package xxx) |
| port deps xxx | (what other packages does package xxx depend upon) |
| port variants xxx | (what are the variants for this port) |
Of these the variants option is most important. Some packages can be built and installed in different ways. Suppose, for example, that some web software that you want to install uses a particular graphics package to manipulate images (make thumbnails and so on) for photo gallery functionality for your web site. This graphics package may also have the ability to display images in a window using X11. But if you don't use X11, you are not interested in this functionality; you would rather build a variant of the package that is smaller and less complicated that does not include the X11 functionality.
The most important port command is, of course to install a new program, namely port -cv install xxx. The -c (cleanup) flag here tells port to clean up all the temporary files created during the installation.
In the subsequent essays you will see all the above fleshed out as we install the various pieces of software that we need.
Updating or uninstalling installed code
Once you have some ports installed, you will occasionally want to update them.
sudo port -v selfupdate
sudo port -v outdated
will tell you what port are out of date and can be updated. This will output something like
The following installed ports are outdated:
teTeX 3.0_0 < 3.0_1
You may then want to update a port. You can do this with a command like
which will behave much like installing the port for the first time, so it will
first upgrade any dependent ports, then will upgrade itself (using the
arguments you used when you first installed it), with the downloading of code,
compiling and so on that you'd expect.
There is a flag, -u, which claims it will uninstall the previous
version of the package, and which it would seem natural to use in this context
--- you install the new version, uninstall the old version, and surely life is
better? Do NOT use this flag. Under the best of conditions it will give various
incomprehensible error messages about why the old version cannot be uninstalled.
If you are really unlucky (as I have been) it will destroy some vital part of
the ports infrastructure, and from that point on nothing will ever work
properly until you toss all your ports and start again from scratch.
You may then want to see all the ports you have installed. You can do this with
which has output like:
base64 @1.3_0 (active)
gawk @3.1.5_1 (active)
ghostscript @8.51_0 (active)
jpeg @6b_1 (active)
mysql5 @5.0.15_0+darwin_8+server
mysql5 @5.0.18_0+darwin_8+server (active)
ocaml @3.08.3_0
ocaml @3.09.1_0 (active)
openssh @4.0_0
openssh @4.3p2_0+darwin_8 (active)
openssl @0.9.7g_0
openssl @0.9.8a_0+darwin_8 (active)
teTeX @3.0_0 (active)
texi2html @1.76_3 (active)
texinfo @4.8_0
texinfo @4.8_1 (active)
zlib @1.2.2_1
zlib @1.2.2_2
zlib @1.2.3_0 (active)
One thing you will notice when seeing what is installed is that once you have upgraded a port or two (if you did not use the -u flag), previous versions of the port are still available in some sense (binaries and so on) on your system, just not active. If you want to get rid of these older versions, you can do so using a command like
where you append the version number of the port you are uninstalling. This version of uninstalling (unlike the -u) has never given me problems apart from occasionally refusing to uninstall a port for reasons that I don't understand, but this, while irritating, has no larger consequences.
What to do in case of disaster
So, as I mentioned with the -u flag, bad things can happen. If so, what do you do?
One very nice aspect to Darwin Ports is that the entire ports world is segregated in /opt/local and has as little interaction as possible with the rest of the world. (Apart from the handling of XWindows, which is completely broken in DarwinPorts, but which fortunately doesn't affect us much.)
Because of this, what I would recommend in case of disaster is the following
-
Type
sudo port -v installed
to get a list of all the ports you have installed and the options you used to create them. Print this, save it to a file, or whatever. With luck your system works well enough that it can still, at least provide you with this information.
-
Move /opt to another name, ie
sudo mv /opt /opt2 -
Reinstall Darwin Ports from scratch following everything I said above.
-
Reinstall all your ports.
-
Copy over whatever modified files you may care about from /opt2 to /opt.
-
At some later point, when you are sure everything works OK, throw away /opt2 ie
sudo rm -rf /opt2

