Installation from source on MacOS - galacticusorg/galacticus GitHub Wiki

Note that these installation instructions are still in beta-testing. Please report failures on the discussion forums.

A beta-release of an installation script (that automates the process of installing Galacticus from source) for MacOS is available in the installationScripts repo. You can find instructions for using this script here.

Install Xcode Command Line Tools

If you don't already have the Xcode command line tools installed, install them now:

if [ ! $(xcode-select -p) ](/galacticusorg/galacticus/wiki/-!-$(xcode-select--p)-); then
    xcode-select --install
fi
export PATH=$PATH:/opt/local/bin:/usr/local/bin

Install MacPorts

Download the appropriate MacPorts for your system. The following will detect your OS version and download and install the correct version.

os_ver=$(sw_vers -productVersion)
IFS='.' read -r -a ver <<< "$os_ver"
if [ "${ver}" -eq 11 ](/galacticusorg/galacticus/wiki/-"${ver}"--eq-11-); then
    macportsversion=2.7.1
    macportsbase=2.7.1-11-BigSur
elif [ "${ver}" -eq 12 ](/galacticusorg/galacticus/wiki/-"${ver}"--eq-12-); then
    macportsversion=2.9.1
    macportsbase=2.9.1-12-Monterey
elif [ "${ver}" -eq 13 ](/galacticusorg/galacticus/wiki/-"${ver}"--eq-13-); then
    macportsversion=2.9.1
    macportsbase=2.9.1-13-Ventura
elif [ "${ver}" -eq 14 ](/galacticusorg/galacticus/wiki/-"${ver}"--eq-14-); then
    macportsversion=2.9.1
    macportsbase=2.9.1-14-Sonoma
else
    echo Unknown MacOS version: ${os_ver}
    exit 1
fi
curl -L https://github.com/macports/macports-base/releases/download/v${macportsversion}/MacPorts-${macportsbase}.pkg --output MacPorts-${macportsbase}.pkg
sudo installer -pkg ./MacPorts-${macportsbase}.pkg -target /
rm ./MacPorts-${macportsbase}.pkg

Install GCC

A recent GCC is required to build Galacticus. The following will install version 12 with an -mp-12 suffix on the executables to avoid possible conflict with other installations of GCC on your system.

sudo port install gcc12

Install Guile

sudo port install guile-3.0

Install GSL

sudo port install gsl

Install libmatheval

curl -L https://github.com/galacticusorg/libmatheval/releases/download/latest/libmatheval-1.1.13.tar.gz --output libmatheval-1.1.13.tar.gz
tar xvfz libmatheval-1.1.13.tar.gz
cd libmatheval-1.1.13
sed -E -i~ s/"#undef HAVE_SCM_T_BITS"/"#define HAVE_SCM_T_BITS 1"/ config.h.in
CC=gcc-mp-12 ./configure --prefix=/usr/local
make -j
sudo make install
cd ..
rm -rf libmatheval-1.1.13.tar.gz libmatheval-1.1.13

Install QHull

curl -L http://www.qhull.org/download/qhull-2020-src-8.0.2.tgz --output qhull-2020-src-8.0.2.tgz
tar xvfz qhull-2020-src-8.0.2.tgz
cd qhull-2020.2
make -j CC=gcc-mp-12 CXX=g++-mp-12
sudo make install
cd ..
rm -rf qhull-2020-src-8.0.2.tgz qhull-2020.2

Install HDF5

curl -L https://support.hdfgroup.org/releases/hdf5/v1_14/v1_14_5/downloads/hdf5-1.14.5.tar.gz --output hdf5-1.14.5.tar.gz
tar -vxzf hdf5-1.14.5.tar.gz
cd hdf5-1.14.5
if [ "${OS_VER}" -eq 13 ](/galacticusorg/galacticus/wiki/-"${OS_VER}"--eq-13-); then
   # For MacOS 13 force use of the classic linker as the new linker does not support the '-commons' option - see https://trac.macports.org/ticket/68194#comment:15
   CC=gcc-15 CXX=g++-15 FC=gfortran-12 LDFLAGS=-Wl,-ld_classic ./configure --prefix=/usr/local --enable-fortran --enable-build-mode=production
else
   CC=gcc-15 CXX=g++-15 FC=gfortran-12                         ./configure --prefix=/usr/local --enable-fortran --enable-build-mode=production
fi
make -j3
sudo make install
cd ..
rm -rf hdf5-1.14.5 hdf5-1.14.5.tar.gz

Install FoX

curl -L https://github.com/galacticusorg/fox/archive/refs/tags/v4.1.3.tar.gz --output FoX-4.1.3.tar.gz
tar xvfz FoX-4.1.3.tar.gz
cd fox-4.1.3
FC=gfortran-mp-12 ./configure --prefix=/usr/local
make -j
sudo make install
cd ..
rm -rf fox-4.1.3 FoX-4.1.3.tar.gz

Install FFTW3

curl -L ftp://ftp.fftw.org/pub/fftw/fftw-3.3.4.tar.gz --output fftw-3.3.4.tar.gz
tar xvfz fftw-3.3.4.tar.gz
cd fftw-3.3.4
F77=gfortran-mp-12 CC=gcc-mp-12 ./configure --prefix=/usr/local
make -j
sudo make install
cd ..
rm -rf fftw-3.3.4 fftw-3.3.4.tar.gz

Install ANN

curl -L http://www.cs.umd.edu/~mount/ANN/Files/1.1.2/ann_1.1.2.tar.gz --output ann_1.1.2.tar.gz
tar xvfz ann_1.1.2.tar.gz
cd ann_1.1.2
sed -E -i~ s/"C\+\+ = g\+\+"/"C\+\+ = g\+\+\-mp\-12"/ Make-config   
make macosx-g++
sudo cp bin/* /usr/local/bin/.
sudo cp lib/* /usr/local/lib/.
sudo cp -R include/* /usr/local/include/.

Install Python dependencies

Galacticus uses Python during compilation to preprocess the source code, and ships various Python scripts under scripts/ for analysis and pipeline tasks. Python ≥ 3.9 is required.

The Python package galacticus (declared in the top-level pyproject.toml) installs the modules under python/ onto the Python import path together with their third-party dependencies — numpy, scipy, h5py, lxml, matplotlib, requests, PyYAML, GitPython, PyPDF2, termcolor — via a single editable install run from the cloned repository's root:

pip3 install -e .

This is sufficient for compiling Galacticus and running its supporting scripts. Two optional extras are also available:

  • pip3 install -e '.[emulation]' — adds dependencies needed by the emulator pipelines under scripts/emulation/.
  • pip3 install -e '.[test]' — adds pytest for running the Python unit-test suite.

Install Galacticus

git clone https://github.com/galacticusorg/galacticus.git
cd galacticus
export GALACTICUS_EXEC_PATH=`pwd`
export FCCOMPILER=gfortran-mp-12
export CCOMPILER=gcc-mp-12
export CPPCOMPILER=g++-mp-12
export LIBRARY_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX15.4.sdk/usr/lib
export GALACTICUS_FCFLAGS="-fintrinsic-modules-path /usr/local/include -fintrinsic-modules-path /usr/local/finclude -L/usr/local/lib -L/opt/local/lib -I/Library/Developer/CommandLineTools/SDKs/MacOSX15.4.sdk/usr/include"
if [ "${ver}" -eq 13 ](/galacticusorg/galacticus/wiki/-"${ver}"--eq-13-); then
    export GALACTICUS_FCFLAGS="$GALACTICUS_FCFLAGS -Wl,-ld_classic"
fi
export GALACTICUS_CFLAGS="-I/usr/local/include -I/opt/local/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX15.4.sdk/usr/include"
export GALACTICUS_CPPFLAGS="-I/usr/local/include -I/opt/local/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX15.4.sdk/usr/include"
make -j Galacticus.exe

Finally

Follow the instructions to download run-time datasets used by Galacticus. You may want to set the above environment variable exports in your ~/.zhsenv so they are set automatically.