Closed2

Apple SiliconのMacでHeroku CLIをネイティブ実行してみる

ピン留めされたアイテム
zundazunda

npmでインストールするHeroku CLI

M1 MacBook Air/Ventura 13.2です。

Dev Center記事Heroku CLIのApple Silicon IssuesよりRosettaがないとBad CPU type in executableと言われるとのこと。ですね。

If you don’t want to install Rosetta 2 on your machine, you can install the Heroku npm package globally and use your own Node binary locally. … npm isn’t the recommended install method.

推奨されていない方法なのだそう。でもやってみよう。

Node 18.14.0 LTSが https://nodejs.org/en/download/ から入手可能なようです。macOS Installer (.pkg) 64-bit/ARM64でいいのかな?node-v18.14.0.pkgをダウンロードして、ダブルクリックしてインストールしてみます。

This package will install:

  • Node.js v18.14.0 to /usr/local/bin/node
  • npm v9.3.1 to /usr/local/bin/npm

だそうです。.zprofilePATH/usr/local/binを追加して、

$ node --version
v18.14.0
$ npm --version
9.3.1

よしよし。

$ npm install -g heroku
  :
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/heroku
npm ERR! errno -13
  :

おやおや。sudoします。

$ sudo npm install -g heroku
  :
added 731 packages in 26s
  :
$ heroku --version
 ›   Warning: Our terms of service have changed:
 ›   https://dashboard.heroku.com/terms-of-service
heroku/7.68.0 darwin-arm64 node-v18.14.0

🎉

zundazunda

HomebrewでインストールするHeroku CLI (Bad CPU type in executableで失敗)

Heroku CLIはHerokuをコマンドラインから利用するのに便利なコマンド群で、Node.jsアプリとして書かれていて、macOSではHomebrewでインストールします。

手元のM1 MacBook Air/Ventura 13.2でインストールして試してみました。

$ xcode-select --install
$ brew tap heroku/brew
$ brew install heroku
  :
==> Installing dependencies for heroku/brew/heroku: heroku/brew/heroku-node
==> Installing heroku/brew/heroku dependency: heroku/brew/heroku-node
  :
==> Caveats
==> heroku
To use the Heroku CLI's autocomplete --
  Via homebrew's shell completion:
    1) Follow homebrew's install instructions https://docs.brew.sh/Shell-Completion
        NOTE: For zsh, as the instructions mention, be sure compinit is autoloaded
              and called, either explicitly or via a framework like oh-my-zsh.
    2) Then run
      $ heroku autocomplete --refresh-cache
  OR
  Use our standalone setup:
    1) Run and follow the install steps:
      $ heroku autocomplete

zsh completions have been installed to:
  /opt/homebrew/share/zsh/site-functions

よーし実行だ!

$ heroku --version
/opt/homebrew/bin/heroku: line 45: /opt/homebrew/opt/heroku-node/bin/node: Bad CPU type in executable

でっすよねえ。

とりあえず

$ brew uninstall heroku
$ brew uninstall heroku-node
$ brew untap heroku/brew
このスクラップは1ヶ月前にクローズされました