Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What is going on with this article?
@arai-wa

Homebrew が使う ruby を変える方法

More than 3 years have passed since last update.

環境

$ uname -a
Darwin xxxxxxxx.local 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
$ brew -v
Homebrew 0.9.9 (git revision 5f06; last commit 2016-05-10)
Homebrew/homebrew-core (git revision 908e; last commit 2016-05-11)

環境変数を使う方法

以下の環境変数を設定すると $HOMEBREW_RUBY_PATH の ruby を使ってくれます

export HOMEBREW_DEVELOPER=1
export HOMEBREW_RUBY_PATH=`使いたい ruby のパス`

解説

Homebrew が使う ruby は /usr/local/Library/brew.sh の59行目以降の下記のコードで決められています。

if [[ -z "$HOMEBREW_DEVELOPER" ]]
then
  unset HOMEBREW_RUBY_PATH
fi

HOMEBREW_SYSTEM="$(uname -s)"
case "$HOMEBREW_SYSTEM" in
  Darwin) HOMEBREW_OSX="1";;
  Linux) HOMEBREW_LINUX="1";;
esac

if [[ -z "$HOMEBREW_RUBY_PATH" ]]
then
  if [[ -n "$HOMEBREW_OSX" ]]
  then
    HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby"
  else
    HOMEBREW_RUBY_PATH="$(which ruby)"
    if [[ -z "$HOMEBREW_RUBY_PATH" ]]
    then
      odie "No Ruby found, cannot proceed."
    fi
  fi
fi

HOMEBREW_DEVELOPER とは、 man brew によれば
If set, Homebrew will print warnings that are only relevant to Homebrew developers (active or budding).
という効果があるそうです。

感想

上述の /usr/local/Library/brew.sh を書き換えたり /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby を置き換えたりする手もありますが、
少なくとも一時的に変更するならこの環境変数の方法が楽だと思います。

1
Help us understand the problem. What is going on with this article?
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
arai-wa

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
1
Help us understand the problem. What is going on with this article?