(Last update: 08-May-2017)

What follows is a description of the procedure I have followed to have CFITSIO working under Mac OS X and Linux.

Mac users

One of the easiest way to install CFITSIO is to make use of MacPorts. Check if MacPorts is already working in your system, and if CFITSIO is already installed, trying to execute:
$ port installed cfitsio
If the previous command does not work, you need to install MacPorts first.

I installed MacPorts downloading the "dmg" disk image installation file corresponding to my OS Version (Snow Leopard) from here. After the installation, one needs to execute (in order to ensure you have the latest revisions to the "Portfiles" needed when building and installing ports):
$ sudo port -v selfupdate

Once MacPorts is available, you can trivially install many packages, in particular CFITSIO:
$ sudo port install cfitsio
Note that the previous command can take several minutes if the system detects the need of installing additional packages.

Sometimes it is necessary to specify the version of the compiler. If this is the case, you can see the list of possible variants available and execute the installation by including the selected version:
$ port info cfitsio
$ sudo port install cfitsio +gcc6

The different versions of the CFITSIO library (libcfitsio.*) are installed under: /opt/local/lib. The auxiliary files longnam.h, fitsio.h, fitsio2.h, and drvrsmem.h are placed under: /opt/local/include. The pkg-config file is available at /opt/local/lib/pkgconfig/cfitsio.pc. Some documentation is also installed under: /opt/local/share/doc/cfitsio-3.270 (with the appropriate version number).

Linux users

In Linux I always download the original source code of CFITSIO from its homepage, and install the package manually.
  1. Download the latest Unix .tar file from the homepage (at the time of writing these notes it was cfitsio3270.tar.gz).
  2. Decompress and extract the contents of the distribution file in a source directory. In this sense, I always place the source cfitsio under /usr/local/src. Note that for this opperation it is probably required that you have root privileges, unless you have write access to the directories. I indicate that by changing the prompt symbol from $ to #. You can either log in as root (using su in Fedora and CentOS, or using sudo su in Ubuntu), or use sudo in front of the following commands:
    # cd /usr/local/src
    # mv ~/Downloads/cfitsio3270.tar.gz .
    # tar zxvf cfitsio3270.tar.gz
    The last command will create /usr/local/src/cfitsio and subdirectories.
  3. Generate the make file:
    # ./configure --prefix=/usr
    Note that I have included the option --prefix=/usr in order to control where the library will be installed. Otherwise, by default CFITSIO will be installed under the source directory, which normally is a bad idea because that directory will not be included in the default search path for autotools.
  4. Compile the source files:
    # make
    # make install
    # make clean

The different versions of the CFITSIO library (libcfitsio.*) are installed under: /usr/lib. The auxiliary files longnam.h, fitsio.h, fitsio2.h, and drvrsmem.h are placed under: /usr/include. The pkg-config file is available at /usr/lib/pkgconfig/cfitsio.pc.