Help us understand the problem. What is going on with this article?

Error: formula x.x is already installed To upgrade to x.x.x , run `brew upgrade formula`.

brew update と set -e を一緒に使っていて処理が止まった

開発環境セットアップにて, set -e を使っていると,brew installの部分で処理が止まった.
よく観察してみると,brew updateにて既存のアップデートがある場合にはerrorで返すことが見られた.

状況

intialSetup.sh
set -e
brew install formula # 表題の出力とともにここで止まる.
echo  # brew install でエラー終了することにより実行されないことがある.

落ち着いた解法

packageがあるかどうかを確認してupgradeする.

if brew ls --versions ${formula} ; then 
  brew upgrade ${formula}
else
  brew install ${formula}
fi

コミュニティで報告されていた解法

エラー出力を捨てる.

brew install ${formula} 2>/dev/null && true

installだけ set +e 解除する

set +e
brew install ${formula}
set -e

参考

https://github.com/Homebrew/brew/issues/2491
brew側では,upgrade-if-installedみたいなオプションを実装する予定はないみたい

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした