# Slicer installation on Mac using homebrew

**URL:** <https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933>\
**Category:** Development\
**Created:** [August 23, 2017, 7:48pm UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933 "2017-08-23T19:48:23Z")\
**Posts on this page:** 15\
**Page:** 2

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [September 6, 2017, 5:43pm UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/21 "2017-09-06T17:43:30Z")

</div>

> [@Fernando](#):
>
> Will the script be run immediately after binaries are ready to be downloaded?

Since the script will run from a different machine, at first I will have it run at 8am EST. Is that too late ? Would you prefer to have the package as soon as it is available ?

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [September 6, 2017, 5:54pm UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/22 "2017-09-06T17:54:07Z")

</div>

> [@jcfr](#):
>
> Would you prefer to have the package as soon as it is available ?

That would be optimal, but I don’t think it’s critical.

I was planning to cron a script that constantly (like every half hour) whether the latest version corresponds to the current cask and repair it if needed. I guess something like that would do the trick.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [September 6, 2017, 6:27pm UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/23 "2017-09-06T18:27:30Z")

</div>

> [@Fernando](#):
>
> I was planning to cron a script that constantly (like every half hour) whether the latest version corresponds to the current cask and repair it if needed. I guess something like that would do the trick.

We still need to have a more robust error checking, but the bulk of it is here:

```auto
# Get revision associated with the last successful caskrepair
last_revision=$(curl -# "https://raw.githubusercontent.com/caskroom/homebrew-versions/master/Casks/slicer-nightly.rb" | grep -e "^\s*version" | cut -d"," -f1 | cut -d"." -f4)

[[-z $last_revision]] && echo "Failed to extract revision from slicer-nightly.rb" && exit 1

# Get revision associated with the last macosx package
package_info=$(curl --progress-bar "http://download.slicer.org/find?os=macosx&stability=any")

version=$(echo $package_info | python -c 'import sys, json; print(json.load(sys.stdin)["version"])') && \
revision=$(echo $package_info | python -c 'import sys, json; print(json.load(sys.stdin)["revision"])') && \
bitstream_id=$(echo $package_info | python -c 'import sys, json; print(json.load(sys.stdin)["download_url"])' | cut -d"/" -f3)

[[-z $revision]] && echo "Failed to extract revision from Slicer package info" && exit 1

# If both revision match, we are all set
if [[$last_revision == $revision]]; then
  exit 0
fi

cask-repair --cask-version $version.$revision,$bitstream_id --fail-on-error --blind-submit slicer-nightly

```

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [September 6, 2017, 6:45pm UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/24 "2017-09-06T18:45:54Z")

</div>

Yes, that looks good. However, I think we also need to check whether a PR has already been sent with a call to `cask-repair`. Otherwise it will continue to create PRs until the first is accepted. What about keeping a local copy with info about the last repair?

```auto
# Get revision associated with the last requested update
revision_path="/tmp/slicer-version.txt"
last_requested_revision=`cat $revision_path`

[[-z $last_requested_revision]] && echo "Failed to extract revision from $revision_path" && exit 1

# Get revision associated with the last macosx package
package_info=$(curl --progress-bar "http://download.slicer.org/find?os=macosx&stability=any")

version=$(echo $package_info | python -c 'import sys, json; print(json.load(sys.stdin)["version"])') && \
revision=$(echo $package_info | python -c 'import sys, json; print(json.load(sys.stdin)["revision"])') && \
bitstream_id=$(echo $package_info | python -c 'import sys, json; print(json.load(sys.stdin)["download_url"])' | cut -d"/" -f3)

[[-z $revision]] && echo "Failed to extract revision from Slicer package info" && exit 1

# If both revision match, we are all set
if [[$last_requested_revision == $revision]]; then
  exit 0
fi

cask-repair --cask-version $version.$revision,$bitstream_id --fail-on-error --blind-submit slicer-nightly

echo $revision > $revision_path

```

P.S.: sometimes the bitstream ID changes and not the revision number. Why is that?

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [September 6, 2017, 8:03pm UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/25 "2017-09-06T20:03:37Z")

</div>

> [@Fernando](#):
>
> What about keeping a local copy with info about the last repair?

Yeahh. That was I did first … but wanted to have something with no state stored in local file. That will definitively work.

> will continue to create PRs until the first is accepted.

Makes sense

> sometimes the bitstream ID changes and not the revision number. Why is that?

If between Day 1 and Day 2 there is no commit done, we still build the package and upload it. Then, you will have the same revision but different id.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 6, 2017, 10:46pm UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/26 "2017-09-06T22:46:07Z")

</div>

I would recommend to not update the package immediately when the core installer is ready because by that time extensions are not available yet. Something like 8am Eastern time should work.

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [September 28, 2017, 10:11am UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/27 "2017-09-28T10:11:14Z")

</div>

> [@Fernando](#):
>
> However, I think we also need to check whether a PR has already been sent with a call to cask-repair. Otherwise it will continue to create PRs until the first is accepted.

Actually, a PR won’t be created if there’s also one pending, the command will just fail. So I guess the script can be safely run daily without the local copy of the last submitted version.

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [June 19, 2018, 12:39pm UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/28 "2018-06-19T12:39:08Z")

</div>

I keep updating the cask from time to time, but still think it could be done automatically every day: [Slicer installation on Mac using homebrew](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/24?u=fernando)

@jcfr what do you think?

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [June 24, 2019, 3:20pm UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/29 "2019-06-24T15:20:14Z")

</div>

I might be the only person in the world updating Slicer with brew, but in case someone else is interested, I just submitted a PR so that the cask for the nightly version doesn’t need to be updated every day: [https://github.com/Homebrew/homebrew-cask-versions/pull/7538](https://github.com/Homebrew/homebrew-cask-versions/pull/7538)

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [June 25, 2019, 6:55am UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/30 "2019-06-25T06:55:39Z")

</div>

> [@Fernando](#):
>
> I might be the only person in the world updating Slicer with brew

You are not the only one

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [August 1, 2019, 2:19pm UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/31 "2019-08-01T14:19:00Z")

</div>

FYI Slicer nightly `slicer-nightly` can be installed by running:

```auto
brew cask install slicer-nightly

```

and upgraded:

```auto
brew cask upgrade slicer-nightly

```

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [August 22, 2019, 7:13am UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/32 "2019-08-22T07:13:08Z")

</div>

In the last upgrade I have obtained:

```bash
==> Installing Cask slicer-nightly
==> Purging files for version latest of Cask slicer-nightly
Error: No such file or directory @ rb_sysopen - /usr/local/Caskroom/slicer-nightly/.metadata/latest.upgrading/20190806090848.651/Casks/slicer-nightly.rb
Follow the instructions here:
  https://github.com/Homebrew/homebrew-cask#reporting-bugs
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1393:in `initialize'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1393:in `open'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1393:in `copy_file'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:487:in `copy_file'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:404:in `block in cp'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1572:in `block in fu_each_src_dest'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1586:in `fu_each_src_dest0'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:1570:in `fu_each_src_dest'
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/fileutils.rb:403:in `cp'
/usr/local/Homebrew/Library/Homebrew/cask/installer.rb:388:in `save_caskfile'
/usr/local/Homebrew/Library/Homebrew/cask/installer.rb:78:in `stage'
/usr/local/Homebrew/Library/Homebrew/cask/installer.rb:99:in `install'
/usr/local/Homebrew/Library/Homebrew/cask/installer.rb:126:in `reinstall'
/usr/local/Homebrew/Library/Homebrew/cask/cmd/reinstall.rb:13:in `block in run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd/reinstall.rb:7:in `each'
/usr/local/Homebrew/Library/Homebrew/cask/cmd/reinstall.rb:7:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd/abstract_command.rb:36:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:93:in `run_command'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:159:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:124:in `run'
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:9:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:102:in `<main>'

```

Now slicer nightly is broken, it used to work really fine until last week!

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [August 24, 2019, 11:02am UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/33 "2019-08-24T11:02:43Z")

</div>

Hi Alex,

It works for me. If you still have problems, you can create an issue on the [`homebrew-cask` repo](https://github.com/homebrew/homebrew-cask).

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [October 9, 2020, 5:55pm UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/34 "2020-10-09T17:55:14Z")

</div>

PR to update the cask submitted: [https://github.com/Homebrew/homebrew-cask/pull/90632](https://github.com/Homebrew/homebrew-cask/pull/90632)

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [October 12, 2020, 10:40pm UTC](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933/35 "2020-10-12T22:40:21Z")

</div>

PR to update the name of the cask for the ~~nightly~~ preview version: [https://github.com/Homebrew/homebrew-cask-versions/pull/9751](https://github.com/Homebrew/homebrew-cask-versions/pull/9751)

Documentation updated: [https://www.slicer.org/wiki/Documentation/Labs/HomebrewCask](https://www.slicer.org/wiki/Documentation/Labs/HomebrewCask)

[Previous page](https://discourse.slicer.org/t/slicer-installation-on-mac-using-homebrew/933.md?page=1)
