MacPorts 101

by saurav on June 16, 2010

While the Mac OS X provides us easy access to the much-beloved terminal, by itself, it is very limited. Apple does not support or maintain its Terminal or X11/XQuartz applications; it is rather supported by an independent group of developers (see XQuartz wiki). However, as the Mac OS X is built on X11, there is no need to install a complete UNIX OS, it does require quite a bit of work to make your machine Unix-capable. For long, the open-source project Fink has long been our savior. Over the past few years, MacPorts has developed as a very nice alternative to Fink in the last couple years. While both systems serve the same purpose, there are differences that make one or the other more appealing. For e.g., if you only need a handful of applications (and not the entire Red Hat system), MacPorts is much easier and faster to install. It takes a couple minutes, which is miniscule compared to the ~45 mins needed for Fink. The caveat being that while Fink installs most of the basic tools and libraries that will be needed in the future and ‘completely’ builds the Unix environment, MacPorts only creates the basic directory structure during installation. For this reason MacPorts uses less hard disk space as well. Of course, you can build ports from fink in MacPorts and vice versa — it just takes a little more effort. In my experience it also takes 3-4 attempts before you get Fink installation right.

The other (big) advantage of Macports is its more active developer base; hence, the various packages tend to get updated quicker. While it is not necessary to keep your packages updated by the day (or the month), it is always nice not to have to wait months for a fix. The good news is that the Macports port library is becoming as extensive as the fink library despite its late start. Again, if you have the expertise, you can always install fink packages in your Macports system as both are open source.

Pre-requisites: Assuming you have a Mac OS X, get the latest versions of X11 and XCode. That is basically it! Then go to the MacPorts install page, download the dmg, and start building any (or all) of its 7015 ports (in 92 different categories). And have fun!

Basic Commands: The average Macports user needs only a handful of commands to install, upgrade, and remove MacPorts. The MacPorts Guide talks about all of these commands (and more) in more detail. But this should be all you need if you are a basic user. You will need ‘sudo’ for most of these commands, i.e., when write/execute permissions are needed. I have used ’emacs’ as an example for package name.

update macports: port selfupdate
list all available (installed/outdated) ports: port list (installed/outdated)
search available ports: port search emacs
install ports: port install emacs
upgrade all (one) outdated ports: port upgrade outdated (emacs)
uninstall (deactivate) ports: port uninstall (deactivate) emacs
uninstall MacPorts: rm -rf /opt/local/ /Applications/MacPorts/ /Library/Tcl/macports1.0/ /Library/LaunchDaemns/org.macports.*

MacPorts PATH: Ports downloaded via MacPorts will be in ‘/opt/local/bin/’, separate from ports native to X11 (e.g. ls, cd, more, gzip, …) that are stored in ‘/usr/bin/’; MacPorts will automatically add this to your PATH on installation. Of course, if you download a port that already exists in ‘/usr/bin’, it will supersede the older one. No harm done, except for the few kilobytes in hard disk space.

Starting List of ports/apps: While the ports or apps you should download depends on your need, for the normal astronomer, I would recommend the following ports: aspell/ispell, teTeX, auctex, emacs/xemacs, gcc, ghostscript, ghostview, gsed, wget, rsync, tightvnc, perl, python, ruby, R, and gimp; see here for more info on these ports. When you install these ports, a lot more ports and libraries will be installed as dependencies, especially gimp will install a lot of ports. Of course, you should browse through the available ports page. Note that installing these ports will take a while (especially gimp) and might test your patience as each application is built from its source code.

Cleaning old ports/apps: MacPorts tends to NOT uninstall old versions of downloaded ports. This means you are wasting a few GBs of your hard drive; I had 6 GB the first time I cleaned up my MacPorts hierarchy. Run the following to do a clean :

sudo port clean --all installed
sudo port -f uninstall inactive

If you want to see how much you saved, use ‘du -sh /opt’.

Some GUI applications like the Chicken of the VNC, TeXShop, LaTeXiT, and Adium are also available via Macports. Whether you download the GUI by itself or as a port (will be installed in ‘/Applications/Macports/’), the functioning will be the same.

(Based mostly on the Macports guide, wiki, and FAQ).

{ 10 comments… read them below or add one }

1 MIchael Galloy June 16, 2010 at 11:50 am

I have been using Homebrew recently. It is very lightweight and basically builds things as if I had done them by hand (except all I have to do is type “brew install xxx” and it gets all the dependencies). So I don’t have software that gets installed in some weird location, everything is in /usr/local just as if I had done it.

Reply

2 Demitri Muna June 16, 2010 at 6:45 pm

Nice article. A few comments…
Apple keeps a hands-off attitude to XQuartz – they support its development (including financially), but leave it to the community, which seems like a good plan. Apple does maintain certain things like python and perl distributions on the Mac. OS X is *not* built on X11, but rather on Apple’s own Quartz windowing system (based on PDF) which is far more modern. XQuartz is then X11 implemented with a Quartz backing. Several of the applications you list are already part of OS X out of the box (perl, python, gcc, emacs, ruby) – these have been optimised by Apple and should probably be used by the average user. Finally, programs like R are “first-class” citizens on the Mac with full-featured GUIs that aren’t always installed by MacPorts. MacPorts is best for libraries (e.g. fftw) and programs that don’t have native Mac versions.

Reply

3 tim June 17, 2010 at 10:11 pm

a few more comments from a macports contributor:

– the /opt/local v. /usr/local issue has been discussed for years. i believe the macports way is correct so that stuff i do myself goes in /usr/local and doesn’t interfere with what macports does. much like fink with /sw.

– it is useful to have separate versions of python, perl, etc. so that extra extensions and modules you install do not interfere with system tools that expect the system versions to behave in specific ways. i’ve seen a few macs that required a fresh reinstall after someone got too frisky with hacking their system’s python, for example.

– installing software without a package management system like port, brew, rpm, etc. is like coding without a version control system. you can do it, but you will eventually end up in tears. it matters less what you use than that you use one. making your own Portfiles for use with macports is fairly straightforward and the macports site has a guide for how to do so. i have even gotten iraf installed this way. e-mail me if you wish to test it out for yourself.

– i have gotten a few other astro packages included into macports such as sextractor, swarp, scamp, and a few other astromatic.net tools. i’m working on ds9 and several others as time allows.

Reply

4 Steve Murray March 5, 2012 at 5:13 pm

I’d be very happy to install iraf using MacPorts and if you have port files for other astro packages I would be interested in them too.

Thanks,
Steve

5 saurav June 18, 2010 at 12:09 am

Demitri, I agree with you that it is good Apple has left XQuartz to the public. There are some Apple engineers who work on XQuartz in their “spare” time.

Tim, thanks for making the various astro packages available on MacPorts — makes it much easier for us to install and maintain them.

Reply

6 Marcos June 18, 2010 at 7:19 am

I suppose people know about the X11 users list http://lists.apple.com/mailman/listinfo/x11-users there was at least someone titled the “xdarwin maintainer” years ago when I was paying attention and trying to figure it out X11 on Leopard (I remember being sad that full screen mode went away). GranteD I stopped reading long ago so maybe now it’s just apple folks on their own time…

I was going to say “fink doesn’t take 45 minutes to install” but egads, they don’t have a binary installer for 10.6 yet? I loved Fink but the problem there was always when there was a major update to OS X and thus a new version of fink, then suddenly nothing worked well or upgraded properly.

Reply

7 saurav June 21, 2010 at 8:20 pm

A questions for MacPorts and/or Fink users (I assume this problem is common for all of us): as far as I know, you have to build separate directory structures for 32-bit and 64-bit apps; is there any way around it? In particular, integrating perl with cfitsio packages seems to cause problems in this regard, as some of the libraries are only for 32-bit mode (via Leslie H.).

Reply

8 John June 22, 2010 at 5:13 am

saurav: Many Macports pacakges can be built with the “universal” variant, which means they provide both 64 and 32 bit versions in one package. For instance:

$ sudo port install cfitsio +universal
[…]
$ file /opt/local/lib/libcfitsio.dylib
/opt/local/lib/libcfitsio.dylib: Mach-O universal binary with 2 architectures
/opt/local/lib/libcfitsio.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
/opt/local/lib/libcfitsio.dylib (for architecture i386): Mach-O dynamically linked shared library i386

Does that help?

Reply

9 saurav June 22, 2010 at 3:25 pm

Thanks, John. That is very helpful.

Reply

10 Saurav August 26, 2010 at 11:37 pm

MacPorts tends to NOT uninstall old versions of downloaded ports. This means you are wasting a few GBs of your hard drive. Run the following to do a clean :

sudo port clean --all installed
sudo port -f uninstall inactive

Do run du -sh /opt to see how much space you save

Reply

Leave a Comment

Previous post:

Next post: