Mac OsX for (particle) physicists

Here is a tutorial on how to get everything you need up and running on a Mac if you are a particle physicist. The tutorial presumes you need the standard “tools of the trade” and have a freshly bought Mac. This tutorial was made on OsX 10.7.4. So let’s go:

1. Enable the ROOT user

This is something that always proves necessary in the long run. Root user privileges are useful when there is a need to tamper with system files, install some apps (as you will see later) etc. OsX sometimes has issues with enabling the root user, so it is best to do it in the beginning, to make sure it all works. Here is a short description of how to do it:

  1. From the Apple menu choose System Preferences….
  2. From the View menu choose Users & Groups.
  3. Click the lock and authenticate as an administrator account.
  4. Click Login Options…
  5. Click the “Edit…” or “Join…” button at the bottom right.
  6. Click the “Open Directory Utility…” button.
  7. Click the lock in the Directory Utility window.
  8. Enter an administrator account name and password, then click OK.
  9. Choose Enable Root User from the Edit menu.
  10. Enter the root password you wish to use in both the Password and Verify fields, then click OK.

2. Basic internet and computer protection

For basic internet traffic control, I suggest Little Snitch. It checks every incoming and outcoming connection and asks for permission of operation. Although a single license (lasts forever) costs 29.95 euro, I highly recommend this product. It also has a nice built-in network monitor so you can see everything that is going on on your computer.

For OsX protection, clean-up etc. you can use CleanMyMac. This nice little app includes more than 50 features (cleanup, caches, junk, app removal, login items etc.). It comes at a price of 29.95 euro for a lifetime, just as Little snitch.

3. Uninstall all the unnecessary applications

Personally, I uninstall all the applications from OsX that I find unnecesarry. These are (in my case) chess, DVD player, iChat, Image Capture, Mail, Photo Booth, QuickTime Player and Safari. Since these are system apps, it is not easy to delete them (can’t drag to trash). You can, however, use some apps like applceaner or CleanMyMac. They don’t do a perfect job, though. It is best if you delete it as root from terminal. For example, to remove Safari, you should:

Quit Safari and Restart
Open Terminal
cd /Applications/
sudo rm -R (or enter su account, then do it)
Enter your password
cd /private/var/db/receipts/
ls -al
Make note of the Safari BOM’s
Remove them One by one Typing: sudo pkgutil –forget PkgNameHere (ex: sudo pkgutil –forget

Next:    Launch Finder (see image below) and search your entire hard drive for the app name (hopefully unique, such as Skype)
You can narrow the search to specific folders or search your whole Mac
Searching “File Name” vs “Contents” usually provides better results.
Click the + button below the search term to add criteria
Click the search criteria drop-down and select “Other…”, then “System files”
Click the “aren’t included” and change to “are included”
Sort by name, kind, date, etc. to identify components of the app
Delete all files and folders related to the app.
Don’t empty your Trash until you’ve determined that everything is working OK.
A reboot might be necessary to completely remove some apps.

4. Web browsing, design, SSH/FTP, e-mail

My usual web browser choice is Firefox. You chose what you like… A html editor with a WYSWYG (what you see is what you get) interface I use is Kompozer. This page was made in it as well. For an FTP/SSH client, I use cyberduck (small and free). Finally, the e-mail client which is absoultely best is Thunderbird.

A few words on updates, add-ons etc.: I use the theme called Silvermel (for free), it gives a nice look to FF/TB. You also want to add the JAVA applet plug-in as well as the QuickTime plug-in and the Flash plugin. Another useful plugin will be RealPlayer. For TB I also use a plug-in called Folderpane Tools, which allows customization of folders. To avoid many of the steps in setting up your accounts in TB, you can port them from your old computer. In /Users/[user name]/Library/Thunderbird/Profiles you can find a folder with a name that looks like [something random].default. Make a copy of the entire contents of this folder on the old computer. On the new computer install Thunderbird and START IT. After starting, close it, and locate your ../Profiles folder. Copy the contents from the old computer. This copies mails, preferences, passwords, themes, extensions etc. Also, get the bookmarks from your old Firefox (.json files). If you go to “Show all Bookmarks -> Import and backup” you can find all you need.

Finally, if you connect to any SSH servers that require keys, or just want to add your key (id_rsa) to connect to anything, don’t forget to put it into .ssh. You should set the permissions on it to 700.

5. Productivity software – Adobe, Office, iWork

To read PDFs, you can use Preview, but it is more convenient to have Adobe Acrobat. The Pro version is very expensive, but you can always just get the free Acrobat Reader. For presentations/documents/charts you can mostly use LaTex, but sometimes other suites come in handy (especially for documents other people make). To maximize compatibility, I use MacOffice and iWork. If you want to go free of charge, you can always use OpenOffice, but it will not have some of the nice options of commercial programs and it will sometimes have compatibility issues.

6. Xcode

Xcode is a collection of compilers, header files, libraries, and software development tools. You definitely want C compiler so that you can install standard Unix software. Xcode is freely available here if you sign up and get a developer account. Starting from Xcode 4.3, the command line tools (the make command, for instance) are no longer shipped with Xcode by default, but they have to be downloaded manually.

To do so, open Xcode, then click on the Xcode bold menu next to the , then Open Developer Tool → More Developer Tools…
You’ll be presented with a webpage where you can download the Command Line Tools for Xcode. Download the dmg, open it, then double-click on the package to install it.

7. (Mac)TeX

I can’t imagine computing without Tex. MacTeX TeXnical working group created an easy-to-install TeX distribution for for MacOSX. Go to The MacTeX Distribution page to download it. The package is very big, but it also contains a Mac-like application that combines the editor and previewer called TexWorks. Bibtex, spell checker etc. are included in the distribution.

Additional software I use includes the KOMA script – to install, unpack the tds file and copy contents (as root) to your texmf tree (mine is in /usr/local/texlive/2011). After the copy, run texhash. Other packages can be installed in the same way. Packages I also use are totcount, layaureo, lettrine and skak.

As for additional fonts, I get the free fonts from exljbris and some additional fonts from Adobe (Garamond Pro, Gill Sans etc.) but you have to pay for these.

8. Application cleanup

Time for some cleanup (important for later steps). You have installed a number of applications – go to the applications pane and sort the apps the way you like in additional folders. I usually make folders like “Programming”, “Productivity”, “Utilities”, “Home” etc. If you make some hard links (like we will do with fink) and then change the application location, things might stop working. So do it now, and then after installing any additional components. Also, I usually install Alfred, which is a nice local search engine and launcher.

9. Porting Unix applications

Mac OS X is based on a variant of Unix called Darwin. Many Unix applications had been ported to Mac OS X already. Fink package manager automates the process of downloading the binary package, or downloading source package, applying a patch, compling, and installing it. Fink was designed carefully as to not disturb or modify the system. It can be uninstalled with a single command ‘sudo rm -r /sw‘. You can use fink to get imagemagick for graphics editing. After installing imagemagick get gimp for all the graphical manipulations you might need.

NOTE: I always install all the software that needs compiling from source in a special folder (usually I create /opt). The reason is simple: this software might not work on other architectures (new computer), so it is best to keep it separated from everything else.

At this point you should create .bash_profile in your home directory (which is /Users/[user name]). I always add the line alias ls=”ls -G” in there to have the ls output in color. You will need this file for complete fink installation. Finally, to install fink:

  1. Get the fink tarball from here
  2. Login as superuser (su)
  3. xcode-select -switch /path/to/
  4. go to wherever you downloaded the tarball
  5. tar xvzf fink-[version]
  6. cd fink-[version]
  7. mkdir -p /opt/fink
  8. chown [username] /opt
  9. chown [username] /opt/fink
  10. ./bootstrap /opt/fink
  11. /opt/fink/bin/
  12. exit
  13. /opt/fink/bin/
  14. Restart the terminal
  15. fink selfupdate-rsync
  16. fink index -f

10. Emacs

You can emacs on Terminal already out of the box, so there is no need for a separate application. Help and shortcuts are available on-line, so… The only issue I have enountered is the page-up/page-down key bindings which only scroll through terminal output (useless). To get the usual Emacs behavior, you can do: Terminal -> Preferences -> Settings -> Keyboard. Double click the “page down” option to edit it. Change Action to “send string to shell” and enter 26 as the string. Save it. Double click the “page up” button to edit it. Change Action to “send string to shell” and enter \33v as the string. Save it.

11. Compilers – (g)fortran and Cross platform make

Although XCode comes with a lot of stuff, it is missing some important compilers you will need – (g)fortran and CMake. You can get a version of gfortan here. CMake is available here (get the newest version). Before running the installation, open a terminal to clean up some symlinks created by the installer of previous CMake versions:

cd /usr/bin
sudo rm -f ccmake cmake cmake-gui cmakexbuild cpack ctest

During the graphical installation just choose the default options and when asked press the button to install the command line links. Both installers will put the software in /usr/local.

12. CERNLIB and calculation support (lapack)

Here is a description of the manual installation of CERNLIBs:

  1. Go to and select one of the sources (compressed tar files) – 2006 is good enough.
  2. cd /
  3. mkdir /opt/cern
  4. copy 3 tar files that you’ve already downloaded (cernlib.tar.gz, cernbin.tar.gz, include.tar.gz)  into cern folder you created.
  5. cd /opt/cern
  6. tar -xvzf *.gz (or unpack one by one)
  7. ln -s 2006 pro
  8. ln -s 2006 new  (2006 is most probable, but you might have another year in the directory, change it accordingly)
  9. Now you should set some system variables: write “export” on the command line to see all fixed system variables and their values which has been declared in the past.
  10. You must change the variables related to CERN. So add these commands into your /Users/[user name]/.bash_profile:
  11. export CERN=<Your Cern Directory>
    export CERN_ROOT=<Your Cern Directory>
    export CERNLIB=$CERN/pro/lib
    export CERNBIN=$CERN/pro/bin
    export PATH=$PATH:$CERNBIN
  12. Check your directory structure – you should have bin, include and lib under 2006, if not, make it so.
  13. rm -f *gz
  14. you will very likely be missing a file called libgfortran.3.dylib or libgfortran.2.dylib (try to start PAW) – locate it on the computer and make a symbolic link from it to wherever PAW is looking for it. If there is no such file, you likely have to get additional software that has it, like gcc453 or R – in this case, I had to make a link to /opt/local/lib/gcc45/libgfortran.3.dylib

13. ROOT and Geant + startup scripts

Now we can install ROOT and Geant. For these, a lot of environment variables have to be exported, so I made a script to do it all. You can find the script at the end of this post. Take note that you can not install ANY combination of Root/Geant. A list of valid combinations is here. You can pick one and enter it in the script. This script now also sets the CERN variables. If you do install Root/Geant, you can remove the “export” commands from your .bash_profile. Next, copy the script somewhere (I use /opt), make it executable (chmod +x and add this line in the bash profile: source /opt/ You can add the switch -n , which automatically selects the preffered triad. Finally, you can install ROOT and GEANT:

  1. source the script
  2. mkdir -p $ROOTSYS
  3. cd $ROOTSYS
  4. svn co$(%5B $ROOT_VER == ‘trunk’ ] || echo tags/)$ROOT_VER .
  5. If prompted to accept the server’s certificate, it is safe to type ‘p’ to accept it permanently and thus avoid subsequent requests.
  6. cd $ROOTSYS
  7. ./configure \
    –with-pythia6-uscore=SINGLE \
    –with-alien-incdir=$GSHELL_ROOT/include \
    –with-alien-libdir=$GSHELL_ROOT/lib \
    –with-monalisa-incdir=”$GSHELL_ROOT/include” \
    –with-monalisa-libdir=”$GSHELL_ROOT/lib” \
    –with-xrootd=$GSHELL_ROOT \
    –with-f77=/usr/local/bin/gfortran \
    –with-clang \
    –enable-minuit2 \
    –enable-roofit \
    –enable-soversion \
    –disable-bonjour \
    –enable-builtin-freetype \
  8. The last step was for Lion with CLang (recommended). You may need other options. Note that disable fink is from ver.5-33-02b onwards.
  9. make -j$MJ
  10. source bin/
  11. When you’re done compiling ROOT, you must source again the script (close and re-open terminal).
  12. mkdir -p $GEANT3DIR
  13. cd $GEANT3DIR
  14. svn co$(%5B $G3_VER == ‘trunk’ ] || echo tags/)$G3_VER .
  15. make -j$MJ
  16. Finally, re-source the script. It should now tell you where the installations are. You can try to run root (just type root).

14. Wolfram Mathematica

Wolfram Mathematica is your all-round set of mathematics tools. There is practically nothing you can’t calculate analitically or numerically in there. It is also an interpreter for a number of languages. Mathematica is available from Wolfram site, but it is quite expensive (1345 Euro LoL)! However, usually your institute has a license, so try to get it there.

15. Miscellaneous Applications

To paste LaTeX equations into Office, use tex2im, a nifty shell script that converts equation in LaTeX to any graphics format. I added the following lines in my .bash_profile:

export TEX2IMBIN=/opt/tex2im

A nice application for creating diagrams of all kinds (and electronics diagrams) is called DIA and can be found on the GNOME pages or on the sourceforge. If tou need to add parton distribution functions to your framework, use this link.

16. Cleanup and pimp-up 🙂

Now it is time to do some cleanup. Here is a list of things that come to mind:

  1. Clean up applications (if you have extras), sort them in folders. You can also sort stuff in launchpad, although that is not so critical.
  2. For pimp-up, you can assign some custom icons to the folders in your applications pane.
  3. Use CleanMyMac to cleanup anything you might not need.
  4. Create a “locate” database: sudo launchctl load -w /System/Library/LaunchDaemons/
  5. Rebuild the OsX Metadata index; you can do this in Alfred -> Preferences -> Advanced -> Rebuild Index
  6. Check the disk for errors and look at disk permissions (in Disk Utility)
  7. For further pimp-up, you can install Wallpaper clocks and get a clock that you like or make your own.
  8. In the end, add some user apps you might want, like Skype and VLC player. I also add CoconutBattery and the Unarchiver, as well as YNAB, a finance application.

17. Backup the disk image

In the end, when it is all done, I strongly recommend you back up the disk image (with or without your data on it, as you prefer). This way you can always restore in the time of need. To backup, you can use Disk Utility found in OsX utilities, but take care – this makes an exact copy of your hard drive (meaning that you have to have the backup AT LEAST the size of your hard drive). Also, you should use this only if you have a mac (or, if you have a PC and want to migrate to another, exactly same PC with the same BIOS settings and version). If you have a PC, you can at least use Time Machine to back up your image and then transfer it to another computer in a time of need. Otherwise, to make an image, you can use a free little app called SuperDuper! which will copy all your files and make a bootable image. For this, you can get a cheap, slow stick, since you’ll likely use it only a couple times (if at all).

You can get this manual in PDF here: Mac OsX for physicists (sorry, it has no hyperlinks since it is just a print of this page – more or less).

Here is the promised startup script (collected, modified and rewritten from other scripts)…

# – by N. Poljak
# This script is meant to be sourced in order to prepare the environment to run
# applications such as ROOT, Geant 3 and CERNLibs.

  # CERN variables
  export CERN=/opt/cern
  export CERN_ROOT=/opt/cern
  export CERNLIB=$CERN/pro/lib
  export CERNBIN=$CERN/pro/bin
  export CERNREV=2006

  # Installation prefix of everything else
  export FRAMEWORK_PREFIX=”/opt/framework”
  export FRAMEWORK_TARGET=”macosx64″

  # Triads in the form “root geant3 cernlibs”.
  TRIAD[1]=”v5-33-02b v1-14 2006″
  # …add more “triads” here without skipping array indices…

  # This is the “triad” that will be selected in non-interactive mode.
  # Set it to the number of the array index of the desired “triad”
  export N_TRIAD=1

# Shows the user a list of configured Framework triads. The chosen triad number is
# saved in the external variable N_TRIAD. A N_TRIAD of 0 means to clean up the
# environment

function FrameMenu() {

  local C R M

  M=”Please select a framework triad in the form 33[1;35mROOT Geant3″
  M=”$M CERNLib33[m (you can also\nsource with 33[1;33m-n33[m to skip”
  M=”$M this menu, or with 33[1;33m-c33[m to clean the environment):”

  echo -e “\n$M\n”
  for ((C=1; $C<=${#TRIAD[@]}; C++)); do
    echo -e ”  33[1;36m($C)33[m “$(NiceTriad ${TRIAD[$C]})
  echo “”;
  echo -e ”  33[1;36m(0)33[m 33[1;33mClear environment33[m”
  while [ 1 ]; do
    echo “”
    echo -n “Your choice: “
    read -n1 N_TRIAD
    echo “”
    expr “$N_TRIAD” + 0 > /dev/null 2>&1
    if [ “$N_TRIAD” != “” ]; then
      if [ $R -eq 0 ] || [ $R -eq 1 ]; then
        if [ “$N_TRIAD” -ge 0 ] && [ “$N_TRIAD” -lt $C ]; then
    echo “Invalid choice.”


# Removes directories from the specified PATH-like variable that contain the
# given files. Variable is the first argument and it is passed by name, without
# the dollar sign; subsequent arguments are the files to search for

function FrameRemovePaths() {

  local VARNAME=$1
  local DIRS=`eval echo \\$$VARNAME`
  local NEWDIRS=””
  local OIFS=”$IFS”
  local D F KEEPDIR

  for D in $DIRS
    if [ -d “$D” ]; then
      for F in $@
        if [ -e “$D/$F” ]; then
    if [ $KEEPDIR == 1 ]; then
      [ “$NEWDIRS” == “” ] && NEWDIRS=”$D” || NEWDIRS=”$NEWDIRS:$D”


  eval export $VARNAME=”$NEWDIRS”


# Cleans leading, trailing and double colons from the variable whose name is
# passed as the only argument of the string

function FrameCleanPathList() {
  local VARNAME=”$1″
  local STR=`eval echo \\$$VARNAME`
  local PREV_STR
  while [ “$PREV_STR” != “$STR” ]; do
    STR=`echo “$STR” | sed s/::/:/g`
  eval export $VARNAME=\”$STR\”

# Cleans up the environment from previously set (DY)LD_LIBRARY_PATH and PATH
# variables

function FrameCleanEnv() {
  FrameRemovePaths PATH xrdgsiproxy root
  FrameRemovePaths LD_LIBRARY_PATH \
  FrameRemovePaths DYLD_LIBRARY_PATH \

  # Unset other environment variables and aliases

# Sets the number of parallel workers for make to the number of cores plus one
# in external variable MJ

function FrameSetParallelMake() {
  MJ=`grep -c bogomips /proc/cpuinfo 2> /dev/null`
  [ “$?” != 0 ] && MJ=`sysctl hw.ncpu | cut -b10 2> /dev/null`
  # If MJ is NaN, “let” treats it as “0”: always fallback to 1 core
  let MJ++
  export MJ

# Exports variables needed to run the Framework, based on the selected triad

function FrameExportVars() {


  # ROOT

  export PATH=”$ROOTSYS/bin:$PATH”
  export PATH=”$PATH:$GSHELL_ROOT/bin”

  # Geant 3


# Prints out the framework paths.

function FramePrintVars() {

  local NOTFOUND=’33[1;31m<not found>33[m’

  # Detect Geant3 installation path
  if [ -x “$GEANT3DIR/lib/tgt_$FRAMEWORK_TARGET/” ]; then

  # Detect ROOT location
  if [ -x “$ROOTSYS/bin/root.exe” ]; then

  # Detect CERNLib location
  if [ -x “$CERN/2006/bin/paw” ]; then

  # Detect CERNLib location
  if [ -x “/opt/fink/bin/apt-get” ]; then

  echo “”
  echo -e ”  33[1;36mCERNLib33[m         $WHERE_IS_CERN”
  echo -e ”  33[1;36mFINKLib33[m         $WHERE_IS_FINK”
  echo -e ”  33[1;36mROOT33[m            $WHERE_IS_ROOT”
  echo -e ”  33[1;36mGeant333[m          $WHERE_IS_G3″
  echo “”


# Separates version from directory, if triad is expressed in the form
# directory(version). If no (version) is expressed, dir is set to version for
# backwards compatiblity

function ParseVerDir() {

  local VERDIR=”$1″
  local DIR_VAR=”$2″
  local VER_VAR=”$3″

  # Perl script to separate dirname/version
  local PERL=’/^([^()]+)\((.+)\)$/ and ‘
  PERL=”$PERL”‘ print “‘$DIR_VAR’=$1 ; ‘$VER_VAR’=$2” or ‘
  PERL=”$PERL”‘ print “‘$DIR_VAR’=’$VERDIR’ ; ‘$VER_VAR’=’$VERDIR'”‘

  # Perl
  eval “unset $DIR_VAR $VER_VAR”
  eval `echo “$VERDIR” | perl -ne “$PERL”`


# Echoes a triad in a proper way, supporting the format directory(version) and
# also the plain old format where dir==ver for backwards compatiblity

function NiceTriad() {
  export D V
  local C=0
  for T in $@ ; do
    ParseVerDir $T D V
    if [ “$D” != “$V” ]; then
      echo -n “33[1;35m$D33[m ($V)”
      echo -n “33[1;35m$D33[m”
    [ $C != 2 ] && echo -n ‘ / ‘
    let C++
  unset D V

# Main function: takes parameters from the command line
function FrameMain() {

  local C T

  # Parse command line options
  while [ $# -gt 0 ]; do
    case “$1” in
      “-q”) OPT_QUIET=1 ;;
      “-v”) OPT_QUIET=0 ;;
      “-n”) OPT_NONINTERACTIVE=1 ;;
      “-i”) OPT_NONINTERACTIVE=0 ;;
      “-c”) OPT_CLEANENV=1; ;;
      “-u”) OPT_DONTUPDATE=1 ;;

  # Always non-interactive+do not update when cleaning environment
  if [ “$OPT_CLEANENV” == 1 ]; then

  [ “$OPT_NONINTERACTIVE” != 1 ] && FrameMenu

  if [ $N_TRIAD -gt 0 ]; then
    for T in ${TRIAD[$N_TRIAD]}
      case $C in
        0) ROOT_VER=$T ;;
        1) G3_VER=$T ;;
        2) CERN_VER=$T ;;
      let C++

    # Separates directory name from version (backwards compatible)
    ParseVerDir $G3_VER    ‘G3_SUBDIR’    ‘G3_VER’

    # N_TRIAD=0 means “clean environment”

  # Cleans up the environment from previous varaiables

  if [ “$OPT_CLEANENV” != 1 ]; then

    # Number of parallel workers (on variable MJ)

    # Export all the needed variables

    # Prints out settings, if requested
    [ “$OPT_QUIET” != 1 ] && FramePrintVars

    if [ “$OPT_QUIET” != 1 ]; then
      echo -e “33[1;33mFrameowrk environment variables cleared33[m”

  # Cleans up artifacts in paths
  FrameCleanPathList LD_LIBRARY_PATH
  FrameCleanPathList DYLD_LIBRARY_PATH
  FrameCleanPathList PATH


# Entry point

FrameMain “$@”
unset FrameCleanEnv FrameCleanPathList FrameExportVars FrameMain FrameMenu FramePrintVars \
  FrameRemovePaths FrameSetParallelMake

This entry was posted in Computing and tagged , , , , , , , . Bookmark the permalink.

4 Responses to Mac OsX for (particle) physicists

  1. Oyunu says:

    Hey there! I could have sworn I’ve been to this website before but after browsing through some of the post I realized it’s new to me.
    Anyways, I’m definitely glad I found it and I’ll be book-marking
    and checking back often!

  2. Wow, superb blog format! How long have you ever been running a blog for? you make blogging look easy. The overall look of your web site is wonderful, let alone the content material!

  3. First of all I would like to say superb blog!
    I had a quick question which I’d like to ask if you don’t mind.
    I was interested to find out how you center yourself and clear
    your head prior to writing. I’ve had trouble clearing my thoughts in getting my thoughts out there. I truly do enjoy writing but it just seems like the first 10 to 15 minutes tend to be wasted simply just trying to figure out how to begin. Any recommendations or tips? Kudos!

  4. nikolapoljak says:

    Thank you all! The blog is new… as for concentration – not sure, I just sit down and write. I sort of have plan before I start, but mostly “it writes itself”.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s