M1ネイティブ対応のhomebrewがリリースされたので、さっそくインストールしてみました。
特に何も考えずに、公式のインストール方法のところに書かれているコマンドラインを実行します。*1
% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" Password: ==> This script will install: /opt/homebrew/bin/brew /opt/homebrew/share/doc/homebrew /opt/homebrew/share/man/man1/brew.1 /opt/homebrew/share/zsh/site-functions/_brew /opt/homebrew/etc/bash_completion.d/brew /opt/homebrew ==> The following new directories will be created: /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks ==> The Xcode Command Line Tools will be installed. Press RETURN to continue or any other key to abort ・ ・ ・
インストール中に、sudoするためのパスワードを聞かれるので、油断しないで待っておきましょう :p
インストールが終わるとWarning: /opt/homebrew/bin is not in your PATH.
とか出ていて、.zprofileになんか設定を書いてねと出てましたので、その通りに追加しときます。
% which brew /usr/local/bin/brew % echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> ${HOME}/.zprofile % . ${HOME}/.zprofile % which brew /opt/homebrew/bin/brew
無事にbrewのパスが更新されました。
さて、homebrewをインストールしたらまずやることと言ったら、rmtreeのインストールです(異論は認める)
% brew tap beeftornado/rmtree ==> Tapping beeftornado/rmtree Cloning into '/opt/homebrew/Library/Taps/beeftornado/homebrew-rmtree'... remote: Enumerating objects: 25, done. remote: Counting objects: 100% (25/25), done. remote: Compressing objects: 100% (14/14), done. remote: Total 181 (delta 9), reused 15 (delta 6), pack-reused 156 Receiving objects: 100% (181/181), 47.98 KiB | 261.00 KiB/s, done. Resolving deltas: 100% (84/84), done. Tapped 1 command and 1 formula (31 files, 106KB).
あっさりとインストールできました。
とりあえず動作確認のために、適当なパッケージをインストールして削除してみましょう。
% brew install watch ==> Downloading https://homebrew.bintray.com/bottles/ncurses-6.2.arm64_big_sur.bottle.tar.gz ==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/111ab64b5ffbe5aebe18096a2ff95e8e8f6426955799181db8338677e8f853e4?response ######################################################################## 100.0% ==> Downloading https://homebrew.bintray.com/bottles/watch-3.3.16.arm64_big_sur.bottle.tar.gz ######################################################################## 100.0% ==> Installing dependencies for watch: ncurses ==> Installing watch dependency: ncurses ==> Pouring ncurses-6.2.arm64_big_sur.bottle.tar.gz ==> Caveats ncurses is keg-only, which means it was not symlinked into /opt/homebrew, because macOS already provides this software and installing another version in parallel can cause all kinds of trouble. If you need to have ncurses first in your PATH, run: echo 'export PATH="/opt/homebrew/opt/ncurses/bin:$PATH"' >> ~/.zshrc For compilers to find ncurses you may need to set: export LDFLAGS="-L/opt/homebrew/opt/ncurses/lib" export CPPFLAGS="-I/opt/homebrew/opt/ncurses/include" ==> Summary 🍺 /opt/homebrew/Cellar/ncurses/6.2: 3,913 files, 9.2MB ==> Installing watch ==> Pouring watch-3.3.16.arm64_big_sur.bottle.tar.gz 🍺 /opt/homebrew/Cellar/watch/3.3.16: 10 files, 153.3KB ==> Caveats ==> ncurses ncurses is keg-only, which means it was not symlinked into /opt/homebrew, because macOS already provides this software and installing another version in parallel can cause all kinds of trouble. If you need to have ncurses first in your PATH, run: echo 'export PATH="/opt/homebrew/opt/ncurses/bin:$PATH"' >> ~/.zshrc For compilers to find ncurses you may need to set: export LDFLAGS="-L/opt/homebrew/opt/ncurses/lib" export CPPFLAGS="-I/opt/homebrew/opt/ncurses/include" % brew deps --installed --tree ncurses watch └── ncurses % brew rmtree watch ==> Examining installed formulae required by watch... / Can safely be removed ---------------------- watch ncurses Proceed?[y/N]: y ==> Cleaning up packages safe to remove Uninstalling /opt/homebrew/Cellar/watch/3.3.16... (10 files, 153.3KB) Uninstalling /opt/homebrew/Cellar/ncurses/6.2... (3,913 files, 9.2MB) % brew deps --installed --tree
問題無さそうですね。
続いて、/usr/localにインストールされたIntel版のパッケージと同じものをインストールしてみましょう。
最初にintel版のインストール済パッケージをダンプします。
% /usr/local/bin/brew bundle dump % cat Brewfile tap "beeftornado/rmtree" tap "homebrew/bundle" tap "homebrew/cask" tap "homebrew/core" brew "ansible" brew "awscli" brew "bash" brew "gcc" brew "git-lfs" brew "jq" brew "ruby" brew "macvim" brew "watch"
手で入れ直しても問題無いくらいのかわいいもんですねorz
このうち、bashは以前書いたとおり、intel版のコマンドラインツールを簡単に切り替えて使うために入れたものなので、今回は入れ直す必要はありません。 あと、rubyも入れた覚えがないw
というわけで、Brewfileからbashとrubyの行を削除してからbrew bundle
します。
% brew bundle ==> Tapping homebrew/bundle Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-bundle'... remote: Enumerating objects: 5704, done. remote: Total 5704 (delta 0), reused 0 (delta 0), pack-reused 5704 Receiving objects: 100% (5704/5704), 1.29 MiB | 538.00 KiB/s, done. Resolving deltas: 100% (3339/3339), done. Tapped 1 command (108 files, 1.7MB). Using beeftornado/rmtree Using homebrew/bundle Tapping homebrew/cask Using homebrew/core Installing ansible Installing awscli Installing gcc Installing git-lfs Installing jq Installing macvim Installing watch Homebrew Bundle complete! 11 Brewfile dependencies now installed.
あ、rmtreeもわざわざ入れなくてもこれでインストールしてくれてますねorz
さて、これでM1ネイティブ版に無事移行できたわけですが、ちょっとgccとpython*2を試してみましょう。
% which gcc /usr/bin/gcc % file $(which gcc) /usr/bin/gcc: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e] /usr/bin/gcc (for architecture x86_64): Mach-O 64-bit executable x86_64 /usr/bin/gcc (for architecture arm64e): Mach-O 64-bit executable arm64e % gcc --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version 12.0.0 (clang-1200.0.32.29) Target: arm64-apple-darwin20.3.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin % which python3 /usr/local/bin/python3 % file $(which python3) /usr/local/bin/python3: Mach-O 64-bit executable x86_64
あれ???
% brew info python3 python@3.9: stable 3.9.1 (bottled) Interpreted, interactive, object-oriented programming language https://www.python.org/ /opt/homebrew/Cellar/python@3.9/3.9.1_8 (3,934 files, 66.6MB) * Poured from bottle on 2021-02-09 at 23:32:51 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/python@3.9.rb License: Python-2.0 ==> Dependencies Build: pkg-config ✘ Required: gdbm ✔, openssl@1.1 ✔, readline ✔, sqlite ✔, tcl-tk ✔, xz ✔ ==> Caveats Python has been installed as /opt/homebrew/bin/python3 Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to `python3`, `python3-config`, `pip3` etc., respectively, have been installed into /opt/homebrew/opt/python@3.9/libexec/bin You can install Python packages with pip3 install <package> They will install into the site-package directory /opt/homebrew/lib/python3.9/site-packages See: https://docs.brew.sh/Homebrew-and-Python ==> Analytics install: 768,550 (30 days), 2,406,022 (90 days), 3,028,682 (365 days) install-on-request: 248,516 (30 days), 718,071 (90 days), 810,290 (365 days) build-error: 0 (30 days)
いや、やっぱりインストールされてますね。
とりあえず別のシェルを起動して実行してみると
% which gcc /usr/bin/gcc % file $(which gcc) /usr/bin/gcc: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e] /usr/bin/gcc (for architecture x86_64): Mach-O 64-bit executable x86_64 /usr/bin/gcc (for architecture arm64e): Mach-O 64-bit executable arm64e % gcc --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version 12.0.0 (clang-1200.0.32.29) Target: arm64-apple-darwin20.3.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin % which python3 /opt/homebrew/bin/python3 % file $(which python3) /opt/homebrew/bin/python3: Mach-O 64-bit executable arm64
gccは変わらないけど、python3はM1用のバイナリが呼ばれるようになりました。
gccは、単に名前の問題のようですね
~ % ls -l /opt/homebrew/bin/gcc-* lrwxr-xr-x 1 sogo admin 33 2 9 23:38 /opt/homebrew/bin/gcc-10 -> ../Cellar/gcc/10.2.0_3/bin/gcc-10 lrwxr-xr-x 1 sogo admin 36 2 9 23:38 /opt/homebrew/bin/gcc-ar-10 -> ../Cellar/gcc/10.2.0_3/bin/gcc-ar-10 lrwxr-xr-x 1 sogo admin 36 2 9 23:38 /opt/homebrew/bin/gcc-nm-10 -> ../Cellar/gcc/10.2.0_3/bin/gcc-nm-10 lrwxr-xr-x 1 sogo admin 40 2 9 23:38 /opt/homebrew/bin/gcc-ranlib-10 -> ../Cellar/gcc/10.2.0_3/bin/gcc-ranlib-10 % gcc-10 --version gcc-10 (Homebrew GCC 10.2.0) 10.2.0 Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
gccを呼ぶと、clangが呼ばれgcc-10を呼ぶとgccが呼ばれるという謎環境ですが、たぶんこのマシンでgccを使う機会はほとんど無いから大丈夫でしょうw