Osservatorio Astrofisico di Arcetri


LAST UPDATE - MACOS SIERRA 10.12.5 (september 2017)

Author: Alessio Turchi - Mail: aturchi AT - Interno: 331

Document rationale

This page wants to be a help for an astronomer using a Mac computer in order to quickly setup its software and start working without having to fight with resolving common issues.


Generally speaking, astronomy work at its very simplest is exploring data, reducind data, writing scripts, plotting and write articles (with LaTex, usually). You may not be involved in all of the aforementioned activities, but surely you will end doing some of them during your career.

You can do your work with almost any computer and operative system (recent enough). Windows is widely used, but it is less widely widespread in science since it is less flexible and quite "unstable". Linux is quite powerfull but many users perceive it as "difficult to use", even if in recent years it became quite user friendly. Mac systems lie somewhere in the middle between Windows and Linux. A Mac is less powerful and flexible than Linux, but it is surely more stable and usable than Windows.

MacOS, the operative system running on (most of) your Mac computers, is a closed source operative system made by Apple Inc. and based on a UNIX architecture . UNIX is a family of operating systems that have a similar interface, similar file system hierarchy and are generally compliant with POSIX specifications. MacOS is officially POSIX certified. There are many Unix-like operative systems so it is difficult to generalize, however beeing unix and posix implies that it is generally easy to port applications from system to system: this means that you are most likely to find that the same shell commands or python scripts are available on your linux server and your Mac notebook, together with very similar utilities. MacOs  is built on top of the XNU kernel, with standard Unix facilities available from the command line interface. On top of the kernel, Apple layered a number of components, including the Aqua interface and the Finder, to complete the GUI-based operating system which is basically what you see and what you use when you face your keyboard.

During the years Apple released may versions of MacOS system, changing the name and, more importantly, changing the very architecture itself. Apple isn't famous for interface stability and legacy support. This guide can't possibly cope with all MacOS versions out there, so we will provide istructions for MacOS Sierra (10.12.X), which is the latest release at the time of writing of this article, and try to keep it updated with all new future releases. You can find which version of MacOS you are running by clicking on the upper left apple-shaped icon on your screen and selecting "About This Mac".

I'll try to avoid giving misleading tips or dangerous informations, wich involve modifying standard settings wich are best left untouched (if you don't know what you're doing). Where multiple choices are possible, I'll try to list the benefits and drawbacks of each one in order to let the user choose freely.


1) First step: configure your shell environment

You will have to use the shell, just bear with it. Since you have to do it, let's try to do it nicely. First you have to learn how to use a command line editor. In this tutorial I will use the editor "nano" since it is simpler than vim. You just have to know that you exit the editor with "Ctrl+x", and if you want to save the file beforehand you have to use "Ctrl+o". This command will open a smal dialog on the bottom of the window. Just hit return ant the file is saved.

Now open a terminal by going into Launchpad and clicking on "terminal". Edit the file .bash_profile that is in your home directory (your terminal starts from your home directory as a default).nano .bash_profile

Insert the following lines in the above file:[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion

# Change the window title of X terminals
case ${TERM} in
                PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
                PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'

if [ -f ~/.bash_aliases ]; then
    source ~/.bash_aliases

if [[ ${EUID} == 0 ]] ; then
    PS1='\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] '
    PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '

trap clear 0

#Fix UTF-8 locale
export LC_ALL="en_US.UTF-8"
export LANG="en_US.UTF-8"

"Ctrl+o", return, "Ctrl+x" and you are done. You will have to return to this file more than once during this tutorial so remember it.

Please notice that each time that you modify your .bash_profile you should quit your terminal and open it again!
You can avoid this by issuing each time the following command:source ${HOME}/.bash_profile


2) Xcode and developer tools

While there are viable alternatives, the standard astronomer that uses a mac will want to install Xcode. This is a suite that contains many developer tools that are used to compile and build programs on a mac. Beware however, Xcode doesn't support fortran. You can get around this problem with some hack, however if you need fortran support I strongly suggest you to skip Xcode installation and see the end of this chapter about "alternatives".

To install Xcode, open the App Store, search for Xcode, click "GET" and then "INSTALL APP". This will download and install Xcode (It is huge, please do this from a fast internet link).

As soon as you are done open a terminal and run the following command:xcode-select --install

You may have to agreee to Xcode license in the terminalsudo xcodebuild -license

Running the above command will ask for your password in the terminal. Insert it and press return.

  • alternatives to Xcode:

If you need fortran support, or simply want to avoid installing Xcode (which I too avoid by the way), you can simply install the gcc compiler with homebrew, which is a topic covered in the following section.


3) First real choice: The package manager

Like many other modern unix systems, MacOS comes with a default package manager called "Apple store". A package manager saves you the hassle of having to download (possibly compile) and install every single needed programs by hand. You simply have to use the search function and select which application you want to install ant it's done: the package manager will install the application you want and all the other programs needed for it to work correctly.

Sadly, the amount of applications available in the Apple store, which are of any use to a scientist, is nearly zero. Apple store sells you apps and games, however it doesn't contain the vast amount of opensource software that you need to work.

In order to install a proper package manager (by unix standards) you have to choose between many different alternatives, none of which are official in any way. This tends to generate unwanted problems, especially during an upgrade of the OS version. For any future upgrade I will try to list here what to do in case problems arise.

MacPorts was the most used package manager until few years ago. Now the general consensus is that MacPorts has been superseded by Homebrew, rightly or wrongly, and that draws more people towards it. As of 2017, I strongly recomend you to install Homebrew. If you really need MacPorts for any reason, it should be possible to have them both installed without problems. However I warn you against trying to install the same program with bot managers, in order to avoid conflicts. Try to use Homebrew whenever possible, and MacPorts only if you are forced to.


To install Homebrew open Launchpad --> Terminal, paste into it the following command and hit return/usr/bin/ruby -e "$(curl -fsSL"

Follow the onscreen instructions and you'll have homebrew installed.

At the end run the commmandbrew update

This will update the program list

 I wrote a short tutorial on the basic usage of Homebrew HERE. I assume you have already red it before continuing through this guide.

Let's start by expanding the repository list in order to include more software. This doesn't install any software so it is safe for any user. Run the following commands in sequence (line by line):brew tap "caskroom/cask"
brew tap "caskroom/drivers"
brew tap "caskroom/fonts"
brew tap "caskroom/versions"
brew tap "homebrew/bundle"
brew tap "homebrew/core"
brew tap "brewsci/science"
brew tap "brewsci/bio"
brew tap "brewsci/base"
brew tap "brewsci/num"

After that run agan the update command:brew update

  • If you didn't install Xcode before:

If you didn't install Xcode before, e.g. because you need fortran or a more recent version of the compiler, you can now install gcc with the following commands:brew install gcc
brew install make
brew install binutils
brew install autoconf
brew install automake

  • Install the standard Linux bash environment and shell tools

If you come from linux, you may want to install the real bash environment and shell tools, such as ls, sed, tar etc... The MacOS versions of these programs are slightly different, outdated and have less flexibility. The following process will ensure that you will have the same enviromnent on your Mac and your linux workstation.brew install coreutils
brew install bash
brew install gnu-sed
brew install gnu-tar
brew install gnu-which
brew install grep
brew install gzip
brew install findutils
brew install diffutils
brew install vim
brew install nano
brew install wget
brew install less
brew install openssh
brew install rsync
brew install unrar
brew install unzip
brew install xz

After installing the above packages, edit your .bash_profile in your home directory and add the following lines.#Use default gnu names

This will enable you to use the standard linux commands without any problem from the shell.

  • Install Xquartz

Many GUI programs ported from linux environment require X11 window system. From MacOS 10.8 the direct support for X11 was dropped. The Xquartz project allows users to continue using the X11 environemnt and linux programs with recent MacOS versions.brew cask install xquartz

In your Applications list now you will find Xquatz installed. Launching the application will start the X11 environment.

  • If you need to visualize postscript files (.ps)

MacOS doesn't natively support postscript files. If you need to open such files, install the following and use "gv <nomefile>" from the command linebrew install ghostscript
brew install gv

You must change permissions of /usr/local folder in order to properly link ghostscript, so you will have to enter your password after the sudo command

  • Install Latex

brew cask install mactex

Add the following lines to your .bash_profile#Tex

You may want to have a latex editor too. Many use texshop, I use latexila (which is more advanced). Chose the one you prefer:brew cask install texshop
brew install latexila

  • Install python

Python is widely used in astronomy. You will need to install basic python support.brew install python
brew install python3
pip install --upgrade pip smartmontools
pip3 install --upgrade pip smartmontools wheel

The first command will install python 2.7 (at the time of writing, which is the default python implementation). The second command will install python 3.6, which is the latest python version. Most of python users are still using pyton 2.x, however there is some software that is written in the new python 3.x, so it is best to have both.

In order to fix a problem with other programs please run the following commands:
mkdir -p ${HOME}/Library/Python/2.7/lib/python/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> ${HOME}/Library/Python/2.7/lib/python/site-packages/homebrew.pth

Invoking the command "python", from the command line will launch pyton2, while to use pyton3 you have to explicitly launch the command "python3".

  • Install Anaconda, Astroconda and IRAF

Many astronomers are familiar with the conda environment. If you want the full featured Anaconda program, there are two versions in the repository, Anaconda and Anaconda2. The first one will install Anaconda3, wich uses as a default pyton3. Anaconda2 will instead set as default pyton2. You can use both python versions with each version of Anaconda, the only difference is the one set as default. If you work mostly with python2 (as most users do) please install Anaconda2, else install Anaconda3brew cask install Caskroom/cask/Anacondaor
brew install Caskroom/versions/anaconda2

If you don't need the full Anaconda (~1Gb) but simply want a basic conda environment (~100Mb) you can install Miniconda insteaf of Anaconda. As above, there are two versions Miniconda and Miniconda2. Just follow the previous advice substituting Miniconda with Anaconda.

Depending of which version of the conda environment you installed, you must insert one of the following lines into your .bash_profileexport PATH="~/miniconda2/bin:$PATH"
export PATH="~/miniconda3/bin:$PATH"
export PATH="~/anaconda2/bin:$PATH"
export PATH="~/anaconda3/bin:$PATH"

You can then install the Astrocondaconda config --add channels

If you simply want to create an astroconda "testenv" (chose your preferred name) environemnt you will use the command:conda create -n testenv stsci

If you want to use IRAF, you must use python 2.7 (as IRAF doesn't work well with python3), so you will use the command:conda create -n testenv python=2.7 stsci pyraf iraf

Then each time you want to access the testenv enviroment you will open a terminal and do:source activate testenv

More info HERE.


4) Install useful programs

Please notice that default security policies restrict installation of apps from developers not officially recognized by Apple. To overcome this limitation, when you have to install an app downloaded from internet (not through homebrew) you have to press "Ctrl", right-click on the app and select "open". In the window that will open up you will see a warning but will have the possibility to select again "open" and go through the install process.

  • Install Imagemagick

Imagemagick is a powerful command line tool for image conversionbrew install imagemagick

  • Install IDL

Many astronomers use IDL. Please read HERE to find more info on how to install IDL. I found out that I had problems in having my IDL installation work with coyote or astron modules. I solved this by inserting the following lines into my .bash_profile:for i in $(find ${HOME}/Applications/exelis/idl/lib -type d);do
  export IDL_PATH="$IDL_PATH:${i}"

In the above example "${HOME}/Applications/exelis/idl/lib" was where I installed IDL modules. Change the path according to your installation directory.

  • Install Iterm2

You may want to install a better terminal application:brew cask install iterm2

  • Install LaTeXiT

LaTeXiT is an equation editor that uses latex to create equationsbrew cask install latexit
Due to a bug in the app it will not show up in Launchpad. You will have to open Finder and click it from the "Applications" folder.

  • Install SAOImage DS9

 SAOImage DS9 is an astronomical imaging and data visualization application, compatible with FITS files.brew install ds9

You can invoke ds9 from the command line, however you can also make an "app" and integrate it with the GUI, in order to be able to associate that app with fits files. It is taken from HERE.
1) Open Automator and choose "Application"
2) Select as an action Library --> Run Shell Script
3) At the top of the window that will open, change "Pass Inputs" to "as arguments"
4) Paste the following lines in the code box overwriting everything else:
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
if [[ $# == 0 ]]; then
    ds9 -cd "~/" &
    ds9 "$@" -cd $(dirname "$1") &
5) Save (File -->Save) in /Application renaming it as DS9
6) Find a FITS file and open the "Get Info" pane.  Choose to Open with Other... and select the DS9 app you've saved from previous, click "Add", then "Change All..." to associate all .FITS files with ds9

  • Install QFitsView

QFitsView is another FITS file viewer similar to DS9. You can download the dmg from the official website HERE. When you click on the dmg file you will see the that you will need to drag & drop in your Application folder.

  • Install Sextractor

SExtractor is a program that builds a catalogue of objects from an astronomical image.
brew install sextractor

Install Firefox

You can install firefox to surf the web, which many users prefer to safari:brew cask install firefox

  • Install MacVim

Many users use a graphical version of the text editor vim. Macvim is an application similar to gvim on Linux. You can install it through homebrew but this will require you to download and install Xcode from the Apple store (just install it, you don't need to run the "xcode-select --install" stuff). I suggest you to download the binary release directly from the website and install it from there. You won't need Xcode for that last option.

If you install Macvim from the downloaded app, you will find it in the /Applications directory on your mac. If you want to launch it from the command line you should issue:
/Applications/ you can make an alias like the following in your .bash_profile and just use the command "mvim":
alias mvim='/Applications/'

  • Install Skype

Another useful applications is Skype:brew cask install skype

  • Manage VPN connections

Tunnelblick is used to easily setup a VPNbrew cask install tunnelblick

  • Install Virtualbox

Do you need a virtual machine for running Windows or Linux? Parallel works well but is expensive. There is Virtualbox which works pretty well and is opensource:brew cask install virtualbox
brew cask install virtualbox-extension-pack

  • Remove boot sound

Do you want to get rid of that annoying sound each time you start up your macbook? Here is the application that will do that for you (beware, you have to use it each time you upgrade something from the App store, some upgrades reinstall the opening chime).brew cask install startninja

  • Install Appcleaner

Appcleaner is a handy tool for uninstalling applications. Simply drag&drop the incon from the application folder into Appcleaner window and it will remove also all the extra cruft installed in hidden places.brew cask install appcleaner

  • Install Pgplot

Many old fortran programs use pgplot libraries to draw plots. Pgplot hasn't been maintained for a decade, so it is hard to install on new computers. However homebrew will do it for you quite easily:brew install pgplot


5) Finish up

As soon as you are done installing what you want through homebrew, you can run this command:brew bundle dump

This command will create a file "Brewfile" in your current directory, which contains all the packages you installed with homebrew together with all all the personal options that you used. This is extremely useful.

If you save this file, if you buy a new mac, or just reset your own, you can reinstall everything (everything installed through homebrew) with a simple command. Simply place the file "Brewfile" in your current directory and run:brew bundle

If at some point you realize that you installed some unneded or unwanted package, with a single command you can uninstall alla packages non listed in the Brewfilebrew bundle cleanup

More info HERE.