# Geant4 in MacBook 19’

**URL:** <https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642>\
**Category:** Getting Started\
**Created:** [October 9, 2020, 6:38am UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642 "2020-10-09T06:38:41Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ken](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Ken](https://geant4-forum.web.cern.ch/u/Ken)\
**Post date:** [October 9, 2020, 6:38am UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642/1 "2020-10-09T06:38:41Z")

</div>

Hi everyone:

I’m a master student who is focus on medical physics. I wanna install Geant4 in my MacBook 19’ , does it work ? Do I need other packages installed in my Mac? Does anyone can help me? Thanks a lot

---

<div class="post-metadata">

**Author:** ![bmorgan](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/bmorgan/32/7_2.png) [@bmorgan](https://geant4-forum.web.cern.ch/u/bmorgan)\
**Post date:** [October 9, 2020, 8:03am UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642/2 "2020-10-09T08:03:36Z")

</div>

Geant4 is supported on macOS, so yes. The easiest way to install to begin using it is through the Homebrew or Conda package managers:

- [https://brew.sh](https://brew.sh)
- [https://docs.conda.io/projects/conda/en/latest/](https://docs.conda.io/projects/conda/en/latest/)
  - [https://anaconda.org/conda-forge/geant4](https://anaconda.org/conda-forge/geant4)

---

<div class="post-metadata">

**Author:** ![Ken](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Ken](https://geant4-forum.web.cern.ch/u/Ken)\
**Post date:** [October 9, 2020, 10:02am UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642/3 "2020-10-09T10:02:20Z")

</div>

Hi Bmorgan:

Thanks for your reply and help so soon.

so you mean I can donwload homebrew or conda to install the g4?

which one is better fit both( GEANT4 AND PTSIM?)

thanks

---

<div class="post-metadata">

**Author:** ![bmorgan](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/bmorgan/32/7_2.png) [@bmorgan](https://geant4-forum.web.cern.ch/u/bmorgan)\
**Post date:** [October 9, 2020, 11:30am UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642/4 "2020-10-09T11:30:21Z")

</div>

Yes, just follow the instructions in the links! Homebrew is the easiest as once installed you just need to do `brew install geant4`. That will provide an install of 10.6.2 with multithreading, Qt and GDML support.

I don’t know about “PTSIM”, so you might want to contact the developers of that to see if they have recommendations.

---

<div class="post-metadata">

**Author:** ![Ken](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Ken](https://geant4-forum.web.cern.ch/u/Ken)\
**Post date:** [October 10, 2020, 3:33am UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642/5 "2020-10-10T03:33:11Z")

</div>

I still can’t use brew to install . could you help me install G4? thanks

I use HOMEBREW but its can’t work

 ![截圖 2020-10-10 14.32.47](https://geant4-forum.web.cern.ch/uploads/default/original/2X/b/b9d874ae0ccc31a91c0e030db55aee21d61234bf.jpeg)

Do I download Xcode?

---

<div class="post-metadata">

**Author:** ![bmorgan](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/bmorgan/32/7_2.png) [@bmorgan](https://geant4-forum.web.cern.ch/u/bmorgan)\
**Post date:** [October 12, 2020, 10:30am UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642/6 "2020-10-12T10:30:26Z")

</div>

Yes, you should follow the instructions and install the command line tools. That’s the minimum needed to build code, including Geant4 applications. It’s up to you whether then to also install the full Xcode IDE from the App Store, though I’d recommend it as it’s a good development environment.

---

<div class="post-metadata">

**Author:** ![silveira](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@silveira](https://geant4-forum.web.cern.ch/u/silveira)\
**Post date:** [April 13, 2021, 3:26pm UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642/7 "2021-04-13T15:26:22Z")

</div>

Dear Ben,

Quick question regarding brew: is the version available compatible with Catalina 10.15.7?

I tried to install Geant4 via brew with `brew install geant4`, but I cannot find the formula in brew.sh, but do in brewsci:

[https://github.com/brewsci/homebrew-science/blob/master/Formula/geant4.rb](https://github.com/brewsci/homebrew-science/blob/master/Formula/geant4.rb)

While trying to install it with `brew install brewsci/science/geant4` I get the error below, and the git repo above shows only high\_sierra among the bottles.

Is there a different direction to follow for this installation step?

Cheers Gustavo

(home path replaced by $HOME)

```
$ brew install brewsci/science/geant4
==> Installing geant4 from brewsci/science
==> Downloading https://ghcr.io/v2/homebrew/core/cmake/manifests/3.20.1
Already downloaded: $HOME/Library/Caches/Homebrew/downloads/374a6e8b44a45140803d162f1f24b6ea2d62e699e665193cb35f787abbcc7ff7--cmake-3.20.1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/cmake/blobs/sha256:1875ab07ed5843cdc06368
Already downloaded: $HOME/Library/Caches/Homebrew/downloads/d8c345011c71dfe2fb736da470c638521f90e7ca8196bdaeafe055bfe74e126e--cmake--3.20.1.catalina.bottle.tar.gz
==> Downloading https://archive.org/download/brewsci/bottles-science/geant4-10.3.3.high_si
==> Downloading from https://ia801805.us.archive.org/0/items/brewsci/bottles-science/geant
#=#=-# #                                                                     
curl: (22) The requested URL returned error: 404 
Error: Failed to download resource "geant4"
Download failed: https://archive.org/download/brewsci/bottles-science/geant4-10.3.3.high_sierra.bottle.tar.gz
```

---

<div class="post-metadata">

**Author:** ![bmorgan](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/bmorgan/32/7_2.png) [@bmorgan](https://geant4-forum.web.cern.ch/u/bmorgan)\
**Post date:** [April 13, 2021, 3:40pm UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642/8 "2021-04-13T15:40:11Z")

</div>

Unfortunately, Homebrew [removed Geant4](https://github.com/Homebrew/homebrew-core/pull/66422#discussion_r539382540) as our licence isn’t considered Debian-compatible. We’re looking at adding a custom tap to allow install through `brew`, but this is still WIP.

The documentation should have been updated, but looks like it hasn’t been deployed yet - I’ll chase that up.

---

<div class="post-metadata">

**Author:** ![weller](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/weller/32/3357_2.png) [@weller](https://geant4-forum.web.cern.ch/u/weller)\
**Post date:** [April 13, 2021, 9:11pm UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642/9 "2021-04-13T21:11:24Z")

</div>

You could try the following as a temporary solution:

```
brew create --set-name geant4 --no-fetch https://geant4-data.web.cern.ch/geant4-data/releases/source/geant4.10.07.p01.tar.gz

```

paste this code into the editor (replace everything that was automatically created)

```auto
class Geant4 < Formula
  desc "Simulation toolkit for particle transport through matter"
  homepage "https://geant4.web.cern.ch"
  url "https://geant4-data.web.cern.ch/geant4-data/releases/source/geant4.10.07.p01.tar.gz"
  version "10.7.1"
  sha256 "525161753a3d9c2ad19b25f2eabc8bbede91c236120771bd9c3f4aaac8412e1e"

  depends_on "cmake" => [:build, :test]
  depends_on "expat"
  depends_on "qt@5"
  depends_on "xerces-c"

  # Check for updates in cmake/Modules/Geant4DatasetDefinitions.cmake

  resource "G4NDL" do
    url "https://cern.ch/geant4-data/datasets/G4NDL.4.6.tar.gz"
    sha256 "9d287cf2ae0fb887a2adce801ee74fb9be21b0d166dab49bcbee9408a5145408"
  end

  resource "G4EMLOW" do
    url "https://cern.ch/geant4-data/datasets/G4EMLOW.7.13.tar.gz"
    sha256 "374896b649be776c6c10fea80abe6cf32f9136df0b6ab7c7236d571d49fb8c69"
  end

  resource "PhotonEvaporation" do
    url "https://cern.ch/geant4-data/datasets/G4PhotonEvaporation.5.7.tar.gz"
    sha256 "761e42e56ffdde3d9839f9f9d8102607c6b4c0329151ee518206f4ee9e77e7e5"
  end

  resource "RadioactiveDecay" do
    url "https://cern.ch/geant4-data/datasets/G4RadioactiveDecay.5.6.tar.gz"
    sha256 "3886077c9c8e5a98783e6718e1c32567899eeb2dbb33e402d4476bc2fe4f0df1"
  end

  resource "G4SAIDDATA" do
    url "https://cern.ch/geant4-data/datasets/G4SAIDDATA.2.0.tar.gz"
    sha256 "1d26a8e79baa71e44d5759b9f55a67e8b7ede31751316a9e9037d80090c72e91"
  end

  resource "G4PARTICLEXS" do
    url "https://cern.ch/geant4-data/datasets/G4PARTICLEXS.3.1.1.tar.gz"
    sha256 "66c17edd6cb6967375d0497add84c2201907a25e33db782ebc26051d38f2afda"
  end

  resource "G4ABLA" do
    url "https://cern.ch/geant4-data/datasets/G4ABLA.3.1.tar.gz"
    sha256 "7698b052b58bf1b9886beacdbd6af607adc1e099fc730ab6b21cf7f090c027ed"
  end

  resource "G4INCL" do
    url "https://cern.ch/geant4-data/datasets/G4INCL.1.0.tar.gz"
    sha256 "716161821ae9f3d0565fbf3c2cf34f4e02e3e519eb419a82236eef22c2c4367d"
  end

  resource "G4PII" do
    url "https://cern.ch/geant4-data/datasets/G4PII.1.3.tar.gz"
    sha256 "6225ad902675f4381c98c6ba25fc5a06ce87549aa979634d3d03491d6616e926"
  end

  resource "G4ENSDFSTATE" do
    url "https://cern.ch/geant4-data/datasets/G4ENSDFSTATE.2.3.tar.gz"
    sha256 "9444c5e0820791abd3ccaace105b0e47790fadce286e11149834e79c4a8e9203"
  end

  resource "RealSurface" do
    url "https://cern.ch/geant4-data/datasets/G4RealSurface.2.2.tar.gz"
    sha256 "9954dee0012f5331267f783690e912e72db5bf52ea9babecd12ea22282176820"
  end
  
  resource "G4TENDL" do
    url "https://cern.ch/geant4-data/datasets/G4TENDL.1.3.2.tar.gz"
    sha256 ""
  end

  def install
    mkdir "geant-build" do
      args = std_cmake_args + %w[
        ../
        -DGEANT4_USE_GDML=ON
        -DGEANT4_BUILD_MULTITHREADED=ON
        -DGEANT4_USE_QT=ON
      ]

      system "cmake", *args
      system "make", "install"
    end

    resources.each do |r|
      (share/"Geant4-#{version}/data/#{r.name}#{r.version}").install r
    end
  end

  def caveats
    <<~EOS
      Because Geant4 expects a set of environment variables for
      datafiles, you should source:
        . #{HOMEBREW_PREFIX}/bin/geant4.sh (or .csh)
      before running an application built with Geant4.
    EOS
  end

  test do
    system "cmake", share/"Geant4-#{version}/examples/basic/B1"
    system "make"
    (testpath/"test.sh").write <<~EOS
      . #{bin}/geant4.sh
      ./exampleB1 run2.mac
    EOS
    assert_match "Number of events processed : 1000",
                 shell_output("/bin/bash test.sh")
  end
end

```

if you need to correct things:

```
brew edit geant4

```

afterwards, fire up (edit:)

```
brew install --build-from-source geant4

```

If you don’t want to interfere with “official” formula names etc, replace geant4 in the brew commands with something else, e.g. mygeant4

expert move: update the datasets to current versions by simply changing the version number in the url. this will throw an error message when installing where you can copy the updated sha256, and place into the formula (brew edit geant4). repeat until no more error messages…

note: this is simply the content I get when I display the content of the geant4 formula on my machine. I have manually changed the file to get the newest version, probably back when it was still available(?). Don’t know if that works… let me know if it does 🙂

---

<div class="post-metadata">

**Author:** ![silveira](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@silveira](https://geant4-forum.web.cern.ch/u/silveira)\
**Post date:** [April 15, 2021, 12:18pm UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642/10 "2021-04-15T12:18:25Z")

</div>

Dear weller,

Thanks a lot. It indeed works after minor corrections. I leave it here in case someone tries to install Geant4 via brew 3.1.2. Since brew requires a license, I took the liberty to set it to “public domain” in case you don’t mind 🙂

Cheers, Gustavo

```
class Mygeant4 < Formula
  desc "Simulation toolkit for particle transport through matter"
  homepage "https://geant4.web.cern.ch"
  url "https://geant4-data.web.cern.ch/geant4-data/releases/source/geant4.10.07.p01.tar.gz"
  version "10.7.1"
  sha256 "525161753a3d9c2ad19b25f2eabc8bbede91c236120771bd9c3f4aaac8412e1e"
  license :public_domain

  depends_on "cmake" => [:build, :test]
  depends_on "qt@5"
  depends_on "xerces-c"

  uses_from_macos "expat"

  resource "G4NDL" do
    url "https://cern.ch/geant4-data/datasets/G4NDL.4.6.tar.gz"
    sha256 "9d287cf2ae0fb887a2adce801ee74fb9be21b0d166dab49bcbee9408a5145408"
  end

  resource "G4EMLOW" do
    url "https://cern.ch/geant4-data/datasets/G4EMLOW.7.13.tar.gz"
    sha256 "374896b649be776c6c10fea80abe6cf32f9136df0b6ab7c7236d571d49fb8c69"
  end

  resource "PhotonEvaporation" do
    url "https://cern.ch/geant4-data/datasets/G4PhotonEvaporation.5.7.tar.gz"
    sha256 "761e42e56ffdde3d9839f9f9d8102607c6b4c0329151ee518206f4ee9e77e7e5"
  end

  resource "RadioactiveDecay" do
    url "https://cern.ch/geant4-data/datasets/G4RadioactiveDecay.5.6.tar.gz"
    sha256 "3886077c9c8e5a98783e6718e1c32567899eeb2dbb33e402d4476bc2fe4f0df1"
  end

  resource "G4SAIDDATA" do
    url "https://cern.ch/geant4-data/datasets/G4SAIDDATA.2.0.tar.gz"
    sha256 "1d26a8e79baa71e44d5759b9f55a67e8b7ede31751316a9e9037d80090c72e91"
  end

  resource "G4PARTICLEXS" do
    url "https://cern.ch/geant4-data/datasets/G4PARTICLEXS.3.1.1.tar.gz"
    sha256 "66c17edd6cb6967375d0497add84c2201907a25e33db782ebc26051d38f2afda"
  end

  resource "G4ABLA" do
    url "https://cern.ch/geant4-data/datasets/G4ABLA.3.1.tar.gz"
    sha256 "7698b052b58bf1b9886beacdbd6af607adc1e099fc730ab6b21cf7f090c027ed"
  end

  resource "G4INCL" do
    url "https://cern.ch/geant4-data/datasets/G4INCL.1.0.tar.gz"
    sha256 "716161821ae9f3d0565fbf3c2cf34f4e02e3e519eb419a82236eef22c2c4367d"
  end

  resource "G4PII" do
    url "https://cern.ch/geant4-data/datasets/G4PII.1.3.tar.gz"
    sha256 "6225ad902675f4381c98c6ba25fc5a06ce87549aa979634d3d03491d6616e926"
  end

  resource "G4ENSDFSTATE" do
    url "https://cern.ch/geant4-data/datasets/G4ENSDFSTATE.2.3.tar.gz"
    sha256 "9444c5e0820791abd3ccaace105b0e47790fadce286e11149834e79c4a8e9203"
  end

  resource "RealSurface" do
    url "https://cern.ch/geant4-data/datasets/G4RealSurface.2.2.tar.gz"
    sha256 "9954dee0012f5331267f783690e912e72db5bf52ea9babecd12ea22282176820"
  end

  resource "G4TENDL" do
    url "https://cern.ch/geant4-data/datasets/G4TENDL.1.3.2.tar.gz"
    sha256 "3b2987c6e3bee74197e3bd39e25e1cc756bb866c26d21a70f647959fc7afb849"
  end

  def install
    mkdir "geant-build" do
      args = std_cmake_args + %w[
        ../
        -DGEANT4_USE_GDML=ON
        -DGEANT4_BUILD_MULTITHREADED=ON
        -DGEANT4_USE_QT=ON
      ]

      system "cmake", *args
      system "make", "install"
    end

    resources.each do |r|
      (share/"Geant4-#{version}/data/#{r.name}#{r.version}").install r
    end
  end

  def caveats
    <<~EOS
      Because Geant4 expects a set of environment variables for
      datafiles, you should source:
        . #{HOMEBREW_PREFIX}/bin/geant4.sh (or .csh)
      before running an application built with Geant4.
    EOS
  end

  test do
    system "cmake", share/"Geant4-#{version}/examples/basic/B1"
    system "make"
    (testpath/"test.sh").write <<~EOS
      . #{bin}/geant4.sh
      ./exampleB1 run2.mac
    EOS
    assert_match "Number of events processed : 1000",
                 shell_output("/bin/bash test.sh")
  end
end
```

---

<div class="post-metadata">

**Author:** ![weller](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/weller/32/3357_2.png) [@weller](https://geant4-forum.web.cern.ch/u/weller)\
**Post date:** [April 15, 2021, 1:54pm UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642/11 "2021-04-15T13:54:09Z")

</div>

> [@silveira](#):
>
> Since brew requires a license, I took the liberty to set it to “public domain” in case you don’t mind

I am not sure if that license rather refers to the software that is installed with the formula (and I also think it is only relevant for uploading the formula to “Homebrew/homebrew-core”: [Formula Cookbook — Homebrew Documentation](https://docs.brew.sh/Formula-Cookbook#fill-in-the-license))

Glad it works 🙂

---

<div class="post-metadata">

**Author:** ![silveira](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@silveira](https://geant4-forum.web.cern.ch/u/silveira)\
**Post date:** [April 15, 2021, 2:11pm UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642/12 "2021-04-15T14:11:16Z")

</div>

Sure, it only relies for your local formula, but I’m clarifying it in respect to your code posted here 🙂

---

<div class="post-metadata">

**Author:** ![weller](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/weller/32/3357_2.png) [@weller](https://geant4-forum.web.cern.ch/u/weller)\
**Post date:** [April 15, 2021, 2:33pm UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642/13 "2021-04-15T14:33:22Z")

</div>

my humble contribution was only the minor change from geant4.10.06 to 4.10.07.p01 and some updated sha256 hash values and dataset urls.

I think the real heroes are the developers & maintainers from geant4, such as @bmorgan😃

---

<div class="post-metadata">

**Author:** ![silveira](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@silveira](https://geant4-forum.web.cern.ch/u/silveira)\
**Post date:** [April 16, 2021, 10:39am UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642/14 "2021-04-16T10:39:19Z")

</div>

One more tip: set the environment vars

[https://geant4-userdoc.web.cern.ch/UsersGuides/InstallationGuide/BackupVersions/V10.4/html/postinstall.html#required-environment-settings-on-windows](https://geant4-userdoc.web.cern.ch/UsersGuides/InstallationGuide/BackupVersions/V10.4/html/postinstall.html#required-environment-settings-on-windows)

---

<div class="post-metadata">

**Author:** ![bmorgan](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/bmorgan/32/7_2.png) [@bmorgan](https://geant4-forum.web.cern.ch/u/bmorgan)\
**Post date:** [July 2, 2022, 4:55pm UTC](https://geant4-forum.web.cern.ch/t/geant4-in-macbook-19/3642/15 "2022-07-02T16:55:05Z")

</div>

Closed on July 2, 2022, 4:55pm UTC


