From Unix to Mac OS X

* Introduction
This document targets users of Unix-like operating systems (e.g., Linux, Solaris, BSD, etc.; I'll just use "Unix" below) who are moving to Mac OS X, and who expect to do a lot of Unix command line computing, including scientific software development. It especially targets users with a cross-platform workflow, i.e., users who will be working on projects both on their OS X Mac and on Unix machines. It aims to help such users become productive in OS X as quickly as possible, while providing them with background information and pointers guiding them beyond first steps.
This document is not a Mac OS primer; it presumes you've already set up your Mac and gotten the hang of the basics of OS X. You should already know what the Finder and Dock are, for example. It is also not a Unix primer for Mac users; it presumes readers are comfortable with the command line and know about Unix software development.
This document is a dynamic HTML outline (it's an export of an OmniOutliner outline where I've compiled various Unix-OS X notes). The triangular "handles" on subsequent sections can be clicked to expand or collapse content. If you're in a rush to get started, the most important material is the "Setting up OS X" section (expanded by default). You'll probably also want to at least skim these sections before you get too far along:
Background: The OS X file system
Background: Software installation
Background: System maintenance — For disk repair and data backup resources
Shell usage: Terminal, X11/xterm, and Console
Shell usage: .bashrc, .profile, and xterm
Scripting in OS X: AppleScript and opening Terminal windows
These notes are a work-in-progress, and a few sections are schematic or just stubs. I hope they're useful despite the rough edges! For a much briefer document with similar aims, see John Vernaleo's OS X as a Unix workstation (aimed at astronomers). For an alternative, similarly lengthy take on this topic, see William Scott's Basics aspects of scientific computing on OS X (aimed at crystallographers).
—Tom Loredo
> Background
> Shell usage
> Scripting in OS X
V Setting up OS X
Your Mac comes ready to use—for most users! For Unix-savvy users who plan to spend lots of time in a terminal, and who plan to develop software, there's a bit of work to be done to get a usable Unix development environment. Here are my suggestions for how to set up your Mac to quickly get productive.
* Partition your hard drive
Your Mac comes with its hard drive formatted as a single partition. This is most likely fine for most users. But if you think you may want to use multiple partitions, now is the time to plan your hard drive organization. OS X's Disk Utility application (mentioned above, in Background: System maintenance) is the tool to use to partition your hard drive. But it does not support "live" altering of partitions; you'll have to reinstall everything on your hard drive if you use Disk Utility to repartition it. There are 3rd-party tools available that support live partition adjustments, but even those tools recommend backing up all your drive contents before altering a partition. To save yourself extra work, you might as well think hard about partitions now, before you start filling your hard drive with software and documents.
Just as examples, here are three ideas for additional partitions (besides your default OS X system partition) to consider. A Google search for "'OS X' partitions" will turn up other ideas for partitioning.
Bare bones OS - Disk Utility is the "first call" disk repair tool, but it cannot repair the partition it is running from (neither can 3rd-party disk repair tools), so if your main system partition develops a problem, you will need to boot from a different volume to repair it. With a desktop machine, you're likely to have your system installation media handy; you can boot from the OS X install disk and run Disk Utility from it to do any needed repairs. With laptops, you may not have your installation disc handy. If you have lots of spare disk space, consider setting aside a few gigabytes for a "bare bones" OS X installation that you can boot from in the off chance you'll need to repair you main drive. Such a partition might also be handy if you need to test installations of software you are developing into a "clean" environment. Even on my desktop Mac, I maintain such a partition (on a second hard drive).
Media - If you plan on using your Mac for audio or video authoring and editing, consider devoting a partition solely to the large media files you'll be working on, to avoid performance penalties from fragmentation. Ideally you would put such media in a separate drive from your system drive, so your authoring application isn't competing for disk access resources with the media itself. Even if you are not authoring media, but expect to compile a large media library (of music, photos, or video), consider devoting a partition to these files to simplify your backup routine. If you use Apple's software to access and organize your media (iTunes, iPhoto, etc.), you can use each application's Preferences menu item to specify where you'd like to maintain your media store.
Projects - Since OS X stores important directories in a user's home directory, I like to keep all my projects and documents in a separate volume. This insures that I won't mess with the OS X directories in the course of my day-to-day work, and it also simplifies my backup routine: I just have to maintain a clone of the whole Projects volume (I back up my home directory and the OS X system directory less frequently).
If you do repartition your Mac, you'll have to re-install OS X on it. Your Mac should have come with instructions for this. Briefly: boot from your install disc (put the disk in your optical drive, turn on your Mac, and hold down the "C" key); the installer will lead you through the straightforward installation process.
* Run Software Update
Apple may have released updates to OS X since the time it was installed on your Mac. Run Software Update (from the Apple menu) to check for any pending updates; install any you need (for example, you might ignore iPod-related updates if you don't use an iPod). See the System Maintenance section, above, for more info on Software Update.
V Install additional Apple software
* X11
Make sure Apple's X11 server is installed on your Mac. Look for it in Applications/Utilities. If an application named X11 is not there, use your system install media to install it (you will have to click the "Customize" button during the install process to get the menu allowing you to select X11). For very early versions of OS X, you may need to obtain the compatible Apple's X11 as a separate download if it was not included on your install media.
V Xcode/Developer tools from ADC
Apple provides a free suite of developer tools for OS X, known originally as "Developer Tools," but more recently as "Xcode" (also the name of one of the tools in the suite). It includes standard Unix development tools like gcc and gdb, many libraries, as well as numerous sophisticated OS X-specific development tools. It lacks a Fortran compiler, however. To get gcc and other such tools, you must install Xcode.
Your Mac may have come with an Xcode install disc. You should probably ignore it. It is likely that Apple has updated the tools since your disc was pressed, and you'll want to download the latest version of the tools. To do so you'll have to create a free account at Apple's developer web site, Apple Developer Connection (ADC; click on the "Sign Up" link). Once you've registered, log in and go to the Downloads section. Download the most recent Xcode disk image (.dmg file). It will be about a gigabyte in size, so you must do this with a fast connection. Once downloaded, just double-click the downloaded disk image to mount it, double-click on the included package to start Installer, and follow the usual install dialog to install the tools.
Among the libraries installed by Xcode are Apple's versions of LAPACK and BLAS, optimized for Mac architectures, so there is no need for you to install these (or Atlas). The libraries are callable from C, C++, Objective-C, Objective-C++, and Fortran. On Intel Macs, recent versions of Tiger included multithreading support in LAPACK and BLAS (in the Accelerate framework), so they take advantage of multiple cores when available. For information on using these libraries, see Taking advantage of the Accelerate framework. A good source of community support for library usage is the Forums section of MacResearch.org.
The Unix tools will be installed in the usual paths (e.g., /usr/bin/gcc) so you'll be able to access them from the command line in the usual way. The OS X-specific developer applications will be on your system disk in the Developer folder (it has a hammer icon and is accessible from the command line at /Developer). If you are not developing OS X applications, you may safely ignore these applications. However, three of them are worth knowing about even if you are sticking to Unix-style command-line development.
If you anticipate you will be making use of Apple's Xcode applications for your Unix development, or especially if you anticipate doing OS X application development yourself, you should also download the latest version of the ADC Reference Library, which will provide a gigabyte of HTML developer documentation on your hard drive. You can also separately download a collection of the documentation as PDF files.
* Xcode
Xcode is the heart of the Xcode tool suite. You'll find it in Developer/Applications. It is a GUI IDE. It has a syntax-aware editor that supports many languages, including C, C++, Objective-C, Java, Fortran, Perl, and Python. It has good project organization tools, and sophisticated language support for the main OS X development languages (C, C++, Objective-C, Java and Python; 3rd-party plug-ins are available for other languages). It is the default application for opening many source code files, including .c and .cpp files. You may want to use another text editor for your coding, especially if you will be moving between multiple platforms; but if you are coding predominantly on Macs, consider learning to use Xcode, if only as a source code editor.
* FileMerge and opendiff
Xcode includes a very nice graphical version of the Unix "diff" file difference tool, called FileMerge. You'll find it in Developer/Applications/Utilities. If you launch it, it will provide a window where you can drag-and-drop files; comparing them presents them side by side, with highlighting showing the differences. At the command line, the "opendiff" command takes files or directories as arguments, and launches FileMerge to compare them. It has a man page detailing its use.
* Property List Editor (in Utilities)
Also in Developer/Applications/Utilities is a handy basic XML editor called Property List Editor. Many parts of OS X store preferences and other data in XML property lists. You can edit such lists directly with Property List Editor, and you may find it handy for other XML documents that have a similar structure.
* Unix-related Apple docs
While you're at the Apple web site downloading Xcode, grab the following three documents which are useful references for some of the Unix capabilities of OS X. If you've installed the developer documentation from ADC, you'll find HTML and/or PDF versions of these under Developer/ADC Reference Library:
Porting UNIX/Linux Applications to Mac OS X
Command-line Backup Solutions on Mac OS X - This document discusses the nuances of backing up your data via command-line tools, in a manner that preserves OS X metadata. Some of these issues are summarized briefly in the Metadata section, above.
Mac OS X Technology Overview- This document provides more in-depth coverage of the material in the Background section, above, and lots more besides. Of special attention is "Appendix C: Mac OS X Developer Tools." It provides descriptions of both Xcode applications and command-line developer tools. For example, it includes a list of command-line version control tools that ship with OS X (which includes only RCS, CVS, and file comparison tools like diff; more on version control tools below).
V Bear Access
Cornell users should download the OS X Bear Access software from the Bear Access web site. Bear Access includes many tools, and you probably won't be interested in some of them. Some, however, are crucial for Cornell users. You can select which tools to install. Most of them install in a Bear Access folder in your Applications folder. The notable exception is Norton Antivirus, which installs in its own folder in Applications. These are the most important Bear Access applications:
* Kerberos
Kerberos handles authentication for access to various Cornell online resources, most importantly library resources and benefits services. You won't have to pay any special attention to it; it will be launched automatically as required. You will need to know your Cornell login info to use it.
* Norton Antivirus
Macs suffer fewer virus attacks than other computers, but Mac viruses do exist, so it is wise to install Norton Antivirus. Note that it installs with a number of default settings that you may wish to adjust. In particular, by default it will search removable media for viruses when the media is mounted. This can be time consuming and annoying. You can adjust this and other settings via Norton preference panes that get added to System Preferences; you can also access them from the Antivirus application itself.
* Eudora mail client
Bear Access includes a popular OS X mail client called Eudora. Once a commercial application, it has just become open source. OS X includes a very capable and popular mail client called, imaginatively enough, Mail. It's in your Applications folder, but is also put in the Dock by default (it has a postage stamp icon). You needn't install Eudora if you are happy with Mail (or if you handle your email on another computer or via the web). Comparisons are subjective, but a common point of comparison between Mail and Eudora is that Eudora has exceptionally fast search capabilities, so some users with particularly voluminous email favor it. The Mozilla Project's Thunderbird email client is another popular email client for OS X, providing an option that runs under both OS X and Unix; get it from Mozilla.com's Thunderbird site.
* Fetch & dataComet
Bear Access includes OS X applications providing GUI access to sftp and ssh, Fetch and dataComet, respectively. These were crucial back in pre-OS X days, and remain useful for users who prefer GUI interfaces. If you are happy using sftp and ssh from a shell prompt, you needn't bother with Fetch and dataComet.
* Firefox
Bear Access includes an installer for the Gecko-based Firefox web browser. It may not be the most recent version, so you are probably better off getting the latest installer from Mozilla.com's Firefox web site. See the 3rd-party software section, below, for more information about OS X web browsers.
V Essential 3rd-party software
* Fortran compilers and scientific computing tools
As noted above, Xcode does not include a Fortran compiler. At least two free Fortran compilers are available for OS X (g77 and gfortran); commercial Fortran compilers are also available. You can find out about them (and download binary builds of the free ones) at the High Performance Computing for Mac OS X web siteHigh Performance Computing for Mac OS X.
Note that, as of OS 10.4, Xcode installs multiple versions of gcc, with gcc4 active by default. As in a unix environment, you can change the version used by the gcc command via the gcc_select command. It is important to be aware of the version you are using if you are using a free gnu-compatible Fortran compiler. g77 should be used with gcc3, and gfortran with gcc4. Intel-based Macs can only run code built with gcc4, so if you need a free compiler for an Intel Mac, use gfortran, not g77. In general, gcc3 is used for OS 10.3 development (Xcode for 10.3 does not include gcc4), and gcc4 is used for OS 10.4 development.
Intel provides highly regarded commercial optimizing compilers for Intel Macs. They offer both a "Standard" version a "Professional" version that adds an optimized math kernel.Intel® Fortran Compiler 9.1, Standard and Professional, for Mac OS* - Intel® Software Network
V TeX/LaTeX/GhostScript on OS X
There are several web sites with comprehensive coverage of TeX, LaTeX, and related tools for TeX-based document preparation on OS X. Here I will just offer a quick set of pointers.
You will most likely want to install a command-line version of the teTeX package, the standard TeX package available in most Unix environments. If you are using MacPorts or Fink, you can install it via their package managers. Alternatively, you can use i-Installer to install TeX Live—a teTeX superset—in the usual locations you'd find it in a Unix environment. Here I'll briefly cover the i-Installer option; for thorough i-Installer instructions visit Gerben Wierda's TeX on OS X web site (scroll down to "The gwTeX (re)distribution" section; the earlier material is for TeX newbies). See Joseph Slater's Getting Started