MacPorts Under Mac OS X Leopard
Apr 18th, 2008 by abbot
Put simply, MacPorts makes software installation easier under Mac OS X. As you may know by now, I prefer to compile from source important software packages, like those used to create the servers accessed by untrusted sources. That software should be customized to the operating system, environment, and requirements of the organization. By doing so, you make the server more secure and stable. Still, many software packages that support the services, such as awk, glib, etc., can be installed through packages or ports. If you were to configure every piece of software on your server, you would probably end up spending your whole life keeping software up-to-date. That would not be fun. MacPorts makes life considerably easier. It is similar to the FreeBSD ports collection.
A little background. The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac OS X operating system.
Below are some basic instructions on installing and using the ports command. I initially posted this under “Installing Packages under MacPorts.” Later, while wrestling with Leopard, I added some addition information in the post “Backing Up Using Amanda on Mac OS X Leopard Part I.” This post is an attempt to pull together information buried in both posts.
If you upgraded to Leopard, you may run into problems with an the previous copy of MacPorts installed under Tiger. The simplest solution is to do a fresh install of MacPorts. Move /opt/local under another directory (so you have it in case you need to switch back) and reinstall MacPorts. A clean install of Leopard will bypass many problems but for many, upgrades are a fact of life that have to be dealt with.
Installation
As with many things involving computers, to do one thing requires several steps. Installing MacPorts is no different.
1. Install Xcode Tools
Xcode is Apple’s premiere development environment for Mac OS X.
- Download the latest verson of Xcode Tools from Apple’s developer site —do not install an older version from the install disk or some ports may fail to install.
- Run the binary installer.
Notes:
Xcode Tools is neither installed nor updated via the Software Update utility. You will want to makre sure you keep it up to date.
2. Install X Windows (X11)
Apple’s X11 is an optional install (MacPorts’ X11 package is not recommended at this time). If the application X11 is not present in /Applications/Utilities:
- Insert the OS X 10.5 installation DVD and run the package named Additional Software.
- At the software selection window expand the Applications category and click the checkbox beside X11 (and nothing else).
- Click Install to install X11.
- Drag the /Applications/Utilities/X11 icon to your dock —you must open X11 before launching an X11 application.
Notes:
- X Windows (X11) is required for many MacPorts apps and it is highly recommended that you install it even if you don’t plan to run X11 apps immediately.
- The X11SDK is also required to run X11 software, but it is installed by default during the Xcode Tools install above. If you wish to check to see if X11 (X11User) and X11SDK are installed, look in /Library/Receipts for the files X11User.pkg and X11SDK.pkg.
- If you have upgraded to Max OS X Leopard, please check your /usr/lib directory for any libraries ending with a ” 1″ (that is a space followed by 1). For example, “/usr/lib/ruby 1” and “/usr/X11R6 1“. These files are created, possibly as a backup copy, when Leopard or Xcode 3 is installed. If you fail to remove those libraries, you will get an error “i686-apple-darwin9-gcc-4.0.1: 1/lib: No such file or directory.”
3. Set the shell environment
Setting the Unix shell environment is critical for MacPorts to function. In you ~/.profile file, add the MacPorts paths in front of the standard UNIX paths for the default BASH shell. This is done so that if you have utilities or libraries from both MacPorts and OS X’s standard install, the MacPorts libraries will be run instead of the ones provided by Apple. You can change the PATH via the command line with the command:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
You’ll need to add this variable to your ~/.profile to run X11 applications:
export DISPLAY=:0.0
So a ~/.profile file might look like this:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH export DISPLAY=:0.0
Note:
- Changes to ~/.profile do not take effect on the current shell session — they take effect on new sessions so open a new shell session and type ‘env’ to see the path and variable changes.
- Other profile files may take precedence over ~/.profile. If you are using one of the following profile files in your home directory, you will need to merge the contents of it into ~./profile, or vice versa because the shell will ignore one of them:
- ~/.bash_login
- ~/.bash_profile
To verify that your ~/.profile has set your shell environment:
- Open a new terminal window
- Type the command: env
Check to make sure the reported path begins with the MacPorts’ paths as show above. Sample output of command env:
TERM_PROGRAM=Apple_Terminal TERM=xterm-color SHELL=/bin/bash PATH=/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
4. Install MacPorts
To install MacPorts using the binary installer (to /opt/local/ only):
- Download the latest MacPorts .dmg disk image, currently version 1.6.0.
- Run the binary installer.
- Perform the default “easy” install.
A MacPorts’ selfupdate (see below) will automatically update to the latest release if the binary .dmg image is behind the latest released tarball.
To install MacPorts from source (to any path except /usr/local/):
- Download and unzip the latest MacPorts tarball from the MacPorts download area.
- Perform these commands in a terminal window.
cd /usr/local/src wget http://svn.macports.org/repository/macports/downloads/MacPorts-1.6.0/MacPorts-1.6.0.tar.gz tar xzf MacPorts-1.6.0.tar.gz cd MacPorts-1.6.0 ./configure make sudo make install
To see why /usr/local is not a viable install location for MacPorts, see the MacPorts FAQ. Developer releases contain untested code and may have bugs. Use at your own risk.
5. Update MacPorts via selfupdate
The port selfupdate command must be run after a new MacPorts install, and frequently thereafter. The command updates MacPorts with the latest port revisions, and, if necessary, updates MacPorts to the latest release.
- Open a terminal window.
- Execute the MacPorts selfupdate command.
sudo port selfupdate
or for verbose output:
sudo port -d selfupdate
6. Installing Packages
Now you are going to start installing packages under MacPorts. A good place to see what packages have been ported over to MacPorts is to go to the main Darwin Ports Repository. It still has the old name, but it is the MacPorts site. It has a search area where you can enter the package name and find installation instructions.
For example, if you wanted to install the GNU multiple precision arithmetic library (GMP), you would execute the MacPorts install command for GMP.
sudo port install gmp
At this point, you should see the following output:
---> Fetching gmp ---> Attempting to fetch gmp-4.2.1.tar.bz2 from http://ftp.gnu.org/gnu/gmp ---> Verifying checksum(s) for gmp ---> Extracting gmp ---> Configuring gmp ---> Building gmp with target all ---> Staging gmp into destroot ---> Running ranlib on static libraries ---> Installing gmp 4.2.1_4+test ---> Activating gmp 4.2.1_4+test ---> Cleaning gmp
Firewall Problems
For those trying to use MacPorts from a computer behind a corporate firewall, the firewall may block rsync access. To configure MacPorts to use some other method than rsync, do the following:
- Check out a working copy of the ports tree to some place on your hard disk, such as the /usr/local/dports directory. Run portindex command so that ports now find these new ports.
root # svn co http://svn.macports.org/repository/macports/trunk/dports \
/usr/local/dports
root # cd /usr/local/dports
root # portindex /usr/local/dports
- Edit the file /opt/local/etc/macports/sources.conf. Comment out the line starting with “rsync://” and add a new line pointing to your working copy, in URL form. For example: file:///usr/local/dports
Using MacPorts
root # svn co http://svn.macports.org/repository/macports/trunk/dports \ /usr/local/dports root # cd /usr/local/dports root # portindex /usr/local/dports |
Below are a few port commands to help with basic operation and navigation. Please see Mark Duling, Dr. Michael A Maibaum, and Will Barton excellent guide/site, “MacPorts Guide” for more information.
contents
The contents option displays the files that have been installed by a given port. Uninstalled ports will always show no contents.
root # port contents glib2 Port glib2 contains: /opt/local/bin/glib-genmarshal /opt/local/bin/glib-gettextize etc. |
deps
The deps option shows you the dependencies of a port.
root # port deps glib2 glib2 has build dependencies on: pkgconfig glib2 has library dependencies on: gettext libiconv |
install
The option install is used to install a port.
root # port install glib2 Skipping org.macports.activate (glib2 ) since this port is already active ---> Cleaning glib2 |
installed
The installed option displays all installed ports.
root # port installed |
list
The list option is used to get a list of all available ports.
root # port list |
search
The search option is very useful to find port names by partial matches.
root # port search glib2 glib2 devel/glib2 2.14.0 Library with data structure functions and other constructs |
selfupdate
The selfupdate command updates MacPorts with the latest port revisions, and, if necessary, updates MacPorts to the latest release.
root # port selfupdate |
Final Word
MacPorts is a powerful tool that should be used in conjunction with software configuration and installation. As with any skilled craftsperson, use the right tool for the right job. Find a balance between keeping software up-to-date and taking the time to understand the software. To quote Louis Nizer, famous legal wizard, “A man who works with his hands is a laborer; a man who works with his hands and his brain is a craftsman; but a man who works with his hands and his brain and his heart is an artist”. Life is always about using every tool at your disposal, including hands, brain, and heart. Never limit yourself.
[...] you are compiling under Mac OS X, you should be familiar MacPorts (see posting “MacPorts Under Mac OS X Leopard“). Make sure the required libraries libjpeg, libpng, gd, and zlib are installed. The [...]
[...] « Introduction to MySQL MacPorts Under Mac OS X Leopard [...]