Suggestions on how to install Geant4

Download Geant4:

wget https://geant4-data.web.cern.ch/geant4-data/releases/source/geant4-v11.2.1.tar.gz
and extract it:
tar -xvzf geant4-v11.2.1.tar.gz

this will create a folder called: "geant4-v11.2.1/"

Create a folder to compile, one for the installation, and one for the data libraries:
mkdir geant4-v11.2.1-build
mkdir geant4-v11.2.1-install
mkdir geant4-data
go in the building directory, compile and install Geant4:
cd geant4-v11.2.1-build
cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGEANT4_INSTALL_DATA=ON -DGEANT4_INSTALL_DATADIR=../geant4-data  -DGEANT4_BUILD_MULTITHREADED=ON -DGEANT4_USE_GDML=ON -DGEANT4_USE_QT=ON -DCMAKE_INSTALL_PREFIX=../geant4-v11.2.1-install ../geant4-v11.2.1 
ninja
ninja install

Prerequisites and suggested packages to compile Geant4 on Debian/Ubuntu:

sudo apt update 
sudo apt install build-essential ninja-build pkg-config libxerces-c-dev libexpat1-dev cmake git  wget zip unzip curl openssl ca-certificates qtbase5-dev libqt5opengl5-dev libx11-dev libxmu-dev libgl1-mesa-glx qt3d5-dev libxcb-xkb-dev

To have an up to date CMake version on Ubuntu 22.04 LTS (Jammy Jellyfish) you can use the official repository:

wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
sudo apt update
sudo apt install cmake --upgrade
sudo rm /usr/share/keyrings/kitware-archive-keyring.gpg
sudo apt install kitware-archive-keyring
for other Ubuntu versions, follow the official guide

Prerequisites and suggested packages to compile Geant4 on CentOS7:

sudo yum update
to have a recent version of gcc:
sudo yum install -y centos-release-scl centos-release-scl-rh
sudo yum install devtoolset-9
sudo yum install xerces-c xerces-c-devel
sudo yum install cmake3 qt5-qtbase qt5-qtbase-devel ninja-build

optional suggested packages:

sudo yum install emacs
sudo yum install python3 python3-pip python3-numpy

Add to your ~/.barshrc:

. /opt/rh/devtoolset-9/enable
alias cmake='cmake3'
alias python='python3'
alias pip='pip3'

Suggestions on how to compile CMake on CentOS7

If you want to have a newever version of CMake you can compile it:

wget https://github.com/Kitware/CMake/releases/download/v3.26.4/cmake-3.26.4.tar.gz
tar -xvzf cmake-3.26.4.tar.gz
cd cmake-3.26.4/
 ./bootstrap && gmake

Add to ~/.bashrc the line:


export PATH=/home/soft/cmake-3.26.4/bin:$PATH

Prerequisites to compile Geant4 on MacOS:

Install at least the command line developer tootls typing in a terminal:

xcode-select --install

Install Homebrew:

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

install XQuartz (https://www.xquartz.org/) manually or using brew:

brew install --cask xquartz

Install the Geant4 dependencies:

brew install cmake libx11 xerces-c qt@5 Ninja

Note: on Mac most probably you have to add the Qt5 path to cmake adding the flag:

-DCMAKE_PREFIX_PATH="/usr/local/opt/qt5/lib/cmake/"

so that the full cmake command is:

cmake -G Ninja -DCMAKE_PREFIX_PATH="/opt/homebrew/opt/qt@5/lib/cmake/" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGEANT4_INSTALL_DATA=ON -DGEANT4_INSTALL_DATADIR=../geant4-data  -DGEANT4_BUILD_MULTITHREADED=ON -DGEANT4_USE_GDML=ON -DGEANT4_USE_QT=ON  -DCMAKE_INSTALL_PREFIX=../geant4-v11.2.1-install ../geant4-v11.2.1

I suggest you to install also some other usefull packages:

brew install wget emacs

The default shell of MacOs is zsh. The configuration script

geant4-v11.2.1-install/bin/geant4.sh

is designed for the bash shell and does not manage to find the directory where it is I suggest to use bash. You can install it with brew:

brew install bash
then you can execute it as any other program
/usr/local/bin/bash
or modifying the default shell in you terminal. Let me suggest you to have a look at iTerm

If you really want to keep using zsh you can try to solve creating another script in the

geant4-v11.2.1-install/bin/
directory:
emacs geant4-v11.2.1-install/bin/geant4.zsh

and write in it:

#!/bin/zsh
mydir=${0:a:h}
cd $mydir
. ./geant4.sh
cd -

or download it:

wget http://www.roma1.infn.it/~mancinit/Teaching/geant4.zsh

source this file instead of geant4.sh