Building and Installing Geant4 on Linux
Building and Installing from Source
1 | Note: Please make sure to replace all instances of `/home/username/Downloads` with your actual path. This is where your configuration files are stored. |
- Download the Source Code Package
Go to the Geant4 website https://geant4.web.cern.ch/ , click on the download link at the top, select “Source code” and then “Download tar.gz”. Assume that it has been downloaded to the subdirectory /home/username/Downloads
.
On Fedora or Ubuntu, you can also download it via the terminal:
1 | $ wget -P /home/username/Downloads https://gitlab.cern.ch/geant4/geant4/-/archive/v11.2.2/geant4-v11.2.2.tar.gz |
- Extract the Package in Terminal
Now extract the package in terminal
1 | $ tar -xzvf /home/username/Downloads/geant4-v11.2.2.tar.gz -C /home/username/Downloads |
Replace /home/username/Downloads
with your actual path.
Now, the Geant4 source package is located in the subdirectory:
1 | /home/username/Downloads/geant4-v11.2.2 |
This is the path to the extracted files.
- Create a Build Directory
The build directory is used to configure and run the build and store the build products. This directory should not be the same as the source directory or located within the source directory.
1 | $ cd /home/username/Downloads |
Use ls
to confirm the directory structure, and the output should include the following:
1 | $ ls |
Switch to the build directory and configure the build:
1 | $ cd /home/username/Downloads/geant4-v11.2.2-build |
- Set Installation Options (Optional)
You can set during installation to add other installation options. For example, after running CMake as described above, you might want to activate the installation of the Geant4 datasets:
1 | $ cd /home/username/Downloads/geant4-v11.2.0-build |
Do not omit the trailing .
. For more options, such as enabling GUI installation, please refer to:
1 | https://geant4-userdoc.web.cern.ch/UsersGuides/InstallationGuide/html/installguide.html#geant4buildoptions |
Simply replace above codes
1 | $ cmake -DGEANT4_INSTALL_DATA=ON . |
with the corresponding command for your needs. Once the installation is complete, the terminal will output different contents depending on the platform, but the last three lines should be approximately:
1 | -- Configuring done |
This indicates that the configuration is complete. If you did not install the datasets, a warning may be issued, but it does not affect the overall installation.
- Run the Build
First, check the number of processor cores on your device:
1 | $ nproc |
The output number N
represents the number of processor cores on your device. Then run the build:
1 | $ cd /home/username/Downloads/geant4-v11.2.0-build |
If there are no special requirements, you can replace n
with N
; if you wish to perform other tasks during compilation, you can reduce the value of n
appropriately; for example, if your device has a 32-core processor, you can set n
to 32, 30, or even 28, depending on your needs.
If there are errors during configuration, please run:
1 | $ make -jN VERBOSE=1 |
It will output more information to help resolve issues or just to gather additional information.
- Install Geant4
Once the build is complete, you can download Geant4 to the location you specified earlier in CMAKE_INSTALL_PREFIX
:
1 | $ cd /home/username/Downloads/geant4-v11.2.2-install |
You can further check the installation version to confirm whether the installation is complete:
1 | $ /home/username/Downloads/geant4-v11.2.2-install/bin/geant4-config --version |
If the installation is complete, it should output the version number.
- Uninstall
If you need to uninstall, please run:
1 | $ make uninstall |
- Title: Building and Installing Geant4 on Linux
- Author: Albert Cheung
- Created at : 2024-08-13 11:47:47
- Updated at : 2024-09-23 16:03:27
- Link: https://www.albertc9.github.io/2024/08/13/Building-and-Installing-Geant4-on-Linux/
- License: This work is licensed under CC BY-NC-SA 4.0.