Geant4 manual installation on macOS


The following procedure works for
  • Sequoia macOS version 15.4 with M series chip
  • Xcode version 16.3
  • Qt version 6
  • ROOT version 6.34.08
  • Geant4 version 11.3.1

We first explain how to install Geant4 in your "home" directory and then how to use the toolkit. We suggest to read the whole procedure first.
The steps described have been updated from the web site of Igor Semeniouk (LLR/IN2P3/CNRS, France) whom we thank very much.

A) Installation of Geant4


Users (with root access) can install Geant4 (which includes Geant4-DNA) on a Mac M series chip computer following these instructions once for each new fresh Geant4 installation.

If asked, make sure to allow the Terminal application to execute commands and tools.

Instructions in pink depend on user choice.

Instructions in purple depend on the software version installed by the Homebrew package manager.

1) Make sure to run the last version of macOS

2) Install the Xcode development framework

3) Install Xcode command line tools by typing the following command in a terminal:

xcode-select --install

4) Install the Homebrew package manager by typing in a terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

After installation, run the indicated commands to add Homebrew to your PATH. This is needed for the next steps that use brew.

5)
Install the CMake build system by typing in the terminal:

brew install cmake

Note that any
package installed with brew can be removed using brew uninstall package

6) Install the Qt version 6 application development framework by typing in the terminal:

brew install qt

7) Define the PKG_CONFIG_PATH environment variable for Qt by typing in the terminal:

export PKG_CONFIG_PATH=/opt/homebrew/Cellar/qt/6.9.0/lib/pkgconfig/
export PATH=
/opt/homebrew/Cellar/qt/6.9.0/bin:$PATH

8) Install the Xerces-C++ XML parser (needed for the handling of GDML files) by typing in the terminal:

brew install xerces-c

9) Install the ROOT data analysis framework (more details on ROOT with Homebrew here - note that we install here from the source due to errors with macOS 15.4 and Xcode 16.3)

brew install --build-from-source root

10) Download Geant4 version 11.3.1 using git (see Geant4 current version number X.Y.Z such as 11.3.1 at this link).

Note that the file
zutil.patch has to be applied for macOS 15.4. Download the file and place it in your home directory (or where your geant4 directory is located).

cd
git clone https://gitlab.cern.ch/geant4/geant4.git
cd geant4
git checkout v
11.3.1
patch -p1 < ../zutil.patch
cd ..

11) Create a build directory:

cd
mkdir build
cd build


and run CMake to configure the build:

cmake
-DCMAKE_INSTALL_PREFIX=
/Users/yourname/geant4-v11.3.1-install \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DGEANT4_USE_GDML=ON \
-DXERCESC_ROOT_DIR=
/opt/homebrew/Cellar/xerces-c/3.3.0 \
-DGEANT4_USE_QT=ON \
-DGEANT4_USE_QT6=ON \
-DCMAKE_PREFIX_PATH="$(brew --prefix qt@6)" \
-DGEANT4_USE_FREETYPE=ON \
-DGEANT4_INSTALL_EXAMPLES=ON \
-DGEANT4_INSTALL_DATA=ON \
-DGEANT4_USE_SYSTEM_EXPAT=OFF \
-DGEANT4_BUILD_TLS_MODEL=auto \
../geant4

Notes
  • the directory /Users/yourname is the "home" directory from which any terminal session starts (check it by typing pwd in the terminal).
  • when the option -DGEANT4_INSTALL_DATA=ON is selected, Geant4 datasets are automatically downloaded, but the download can sometimes be very slow; instead, you can ignore this option and install all data files manually as explained in the installation instructions (uncompress each dataset file using tar -xvf filename.tar).

12)
Run the build with (e.g., using 10 cores):

cmake --build . --target install -- -j10


B) How to use Geant4


1)
Create a .zshrc file from the terminal in your "home" directory, using for example :

nano .zshrc

and add the following lines
:

#
#Qt
#
export PKG_CONFIG_PATH=
/opt/homebrew/Cellar/qt/6.9.0/lib/pkgconfig/
export PATH=
/opt/homebrew/Cellar/qt/6.9.0/bin:$PATH
#
#ROOT
#
source
/opt/homebrew/Cellar/root/6.34.08/bin/thisroot.sh
#
#Geant4
#
cd
/Users/yourname/geant4-v11.3.1-install/bin
source geant4.sh
#
cd

Save your file with control X key combination and answer Y.

2) Source this file with source .zshrc or start a new terminal (from Monterey macOS, the .zshrc file will be read automatically each time you open a new terminal, making your computer fully configured to use Geant4).

3) As an illustration, if you want to test the dnaphysics extended example (with a build on 10 cores), do the following:

cd
cp -R geant4/examples/extended/medical/dna/dnaphysics .
cd dnaphysics
mkdir build
cd build
cmake ..
make -j
10
./dnaphysics dnaphysics.in
root plot.C

C) Comments


a) After update of Xcode, if the cmake command fails, you may need to relink to MacOSX.sdk. For this, do as follows in a Terminal (assuming that you know your super user password and that you have authorized Terminal to modify Apps):

cd
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
sudo ln -s MacOSX.sdk MacOSX
Y.Z.sdk

where
Y and Z are given by the cmake command error message, for example :

sudo ln -s MacOSX.sdk MacOSX15.2.sdk

b) If, after update of Xcode, the
ROOT installation (based on brew) is failing, try to reinstall it from source using:

brew uninstall root
brew install --build-from-source root


An alternative solution is to install ROOT using
Anaconda. See installation instructions using Conda here.

-
Updated on 09/04/2025