thoughtbot/laptop

MacOS 11.0 Big Sur and/or m1 Apple Silicon support?

wxmn opened this issue · 10 comments

wxmn commented

I know Homebrew, in particular, has some issues running on Apple Silicon (but there are workarounds with Rosetta 2), but I'm just wondering what the status is of this script supporting Big Sur and/or the m1 Macs? Thanks!

Hi! Using the workarounds for Rosetta 2 this script runs without issue on Big Sur and Apple Silicon.

I personally used this workaround and set up a new computer from scratch last night and didn't run into any trouble.

I think it would be good if we update the readme to say as much.

The above workaround I used, runs all of Homebrew and all installed software under Rosetta 2. There is another workaround I have not personally tested that instead of duplicating terminal as Intel, installs a Rosetta 2 version of Homebrew and an Intel version of Homebrew so that some software that supports it can be native for the M1.

Using that workaround it will be more complex for this script to install and stay up to date with what is likely to change a lot over the next few months.

One note is that Homebrew installs to /opt/homebrew on Apple Silicon rather than /usr/local so HOMEBREW_PREFIX probably needs to be dependant on the architecture. Anyone know a good way to detect that?

@jdbann You should use brew shellenv to determine HOMEBREW_PREFIX.

I've got this completely un-battle-tested bit in my local fork:

    arch="$(uname -m)"
    if [[ $arch =~ "arm64" ]]; then
      append_to_zshrc "eval \"\$(/opt/homebrew/bin/brew shellenv)\""
    elif [[ $arch =~ "x84_86" ]]; then
      append_to_zshrc "eval \"\$(/usr/local/bin/brew shellenv)\""
    fi
    source ~/.zshrc

@jamesgecko Thanks for sharing the script. Some adjustments are still needed and in particular, the following section runs before Homebrew gets installed on a new computer:

laptop/mac

Lines 49 to 59 in c3d5a26

HOMEBREW_PREFIX="/usr/local"
if [ -d "$HOMEBREW_PREFIX" ]; then
if ! [ -r "$HOMEBREW_PREFIX" ]; then
sudo chown -R "$LOGNAME:admin" /usr/local
fi
else
sudo mkdir "$HOMEBREW_PREFIX"
sudo chflags norestricted "$HOMEBREW_PREFIX"
sudo chown -R "$LOGNAME:admin" "$HOMEBREW_PREFIX"
fi

This has been working well for me across an M1 and an Intel macOS laptops:

set -eux

# arm64 or x86_64
arch="$(uname -m)"

# Homebrew
if [ "$arch" = "arm64" ]; then
  BREW="/opt/homebrew"
else
  BREW="/usr/local"
fi

if [ ! -d "$BREW" ]; then
  sudo mkdir -p "$BREW"
  sudo chflags norestricted "$BREW"
  sudo chown -R "$LOGNAME:admin" "$BREW"
  curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C "$BREW"
fi

export PATH="$BREW/bin:$PATH"

brew analytics off
brew update-reset
brew bundle --no-lock --file=- <<EOF
brew "gh"
brew "git"
# ...
EOF

# zsh
update_shell() {
  sudo chown -R $(whoami) "$BREW/share/zsh" "$BREW/share/zsh/site-functions"
  chmod u+w "$BREW/share/zsh" "$BREW/share/zsh/site-functions"
  shellpath="$(command -v zsh)"

  if ! grep "$shellpath" /etc/shells > /dev/null 2>&1 ; then
    sudo sh -c "echo $shellpath >> /etc/shells"
  fi

  chsh -s "$shellpath"
}

case "$SHELL" in
  */zsh)
    if [ "$(command -v zsh)" != "$BREW/bin/zsh" ] ; then
      update_shell
    fi
    ;;
  *)
    update_shell
    ;;
esac

# ...

https://github.com/croaky/laptop/blob/main/laptop.sh

Looks like Homebrew 2.6.0 solves the M1 issues.
https://brew.sh/2020/12/01/homebrew-2.6.0/

@brennenawana I think its really Homebrew 3.0 where this all got to the point where it's ready. 2.6 only had partial functionality.

With homebrew 3.0 things are working well now, but there are still some packages that don't yet have ARM packages. Though that number continues to go down.

I've currently installed 3.0 arm version alongside an Intel version. It's unclear to me whether Homebrew will automatically use Rosetta 2 or whether running them alongside each other is going to be the standard way of operating until hopefully it is no longer necessary? I think that will influence how we want the laptop script to set things up.

@croaky are you also running it side by side? Have you found the need to keep an Intel version of brew around?

Overall, things continue to work very well for me with this setup though.

I'm not running side-by-side on the same machine, only Intel Homebrew on Intel machine and Apple Silicon Homebrew on M1 machine.

Based on this, I went back through everything and confirmed I didn't actually have anything that I actually use that was still dependent on Intel builds either.

The existing pull request #597 actually ends up removing the code which is causing problems with Apple Silicon. I'm planning on merging that PR to close that issue unless anyone objects.