Using R after using migration assistant to move from Intel to Apple Silicon M1 returns errors: Bad CPU type in executable and Undefined error: 0

Using R after using migration assistant to move from Intel to Apple Silicon M1 returns errors: Bad CPU type in executable and Undefined error: 0

在使用迁移助手从我的 MacBook Pro 2018 I5 迁移到新的 MacBook Pro 2020 M1 后,我尝试在命令行中 运行 R 简单地使用 R 并得到错误:

/usr/local/bin/R: line 271: /usr/local/Cellar/r/4.0.3/lib/R/bin/exec/R: Bad CPU type in executable
/usr/local/bin/R: line 271: /usr/local/Cellar/r/4.0.3/lib/R/bin/exec/R: Undefined error: 0

我试过了:

sudo rm -rf /Applications/R.app
sudo rm -rf /Library/Frameworks/R.framework
sudo rm /usr/bin/{R,Rscript}
sudo rm -rf /usr/local/bin/R

并成功删除 R,显示:

zsh: command not found: R

然后我尝试用自制软件重新安装 R,但出现如下错误:

Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
Please create a new installation in /opt/homebrew using one of the
"Alternative Installs" from:
  https://docs.brew.sh/Installation
You can migrate your previously installed formula list with:
  brew bundle dump
Error: Git must be installed and in your PATH!
Error: homebrew/science was deprecated. This tap is now empty and all its contents were either deleted or migrated.

我意识到这可能是 git and/or 自制程序问题,所以我使用了 instructions from the homebrew site indicated in the error in the prescribed directory with sudo mkdir homebrew && sudo curl -L https://github.com/Homebrew/brew/tarball/master | sudo tar xz --strip 1 -C homebrew and got the same errors. At this point I updated my Mac OS, to 11.2.2., and found this 。这解决了我所有的问题,我能够升级我的 git,使用 brew 安装 xquartz、R 和 Rstudio:

/usr/sbin/softwareupdate --install-rosetta --agree-to-license
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
arch -x86_64 brew install git
arch -x86_64 brew upgrade git
arch -x86_64 brew install Caskroom/cask/xquartz
arch -x86_64 brew install --cask r
arch -x86_64 brew install --cask rstudio

这是 here 和之前演练中的片段的组合。