Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wxmn opened this issue Nov 23, 2020 · 10 comments · Fixed by #602
Closed

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

wxmn opened this issue Nov 23, 2020 · 10 comments · Fixed by #602

Comments

@wxmn
Copy link

wxmn commented Nov 23, 2020

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!

@cpytel
Copy link
Member

cpytel commented Dec 11, 2020

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.

@jdbann
Copy link

jdbann commented Mar 19, 2021

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?

@jamesgecko
Copy link

@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

@mareksuscak
Copy link

mareksuscak commented Jun 23, 2021

@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

@croaky
Copy link
Contributor

croaky commented Jun 24, 2021

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

@brennenawana
Copy link

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

@cpytel
Copy link
Member

cpytel commented Jul 23, 2021

@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.

@croaky
Copy link
Contributor

croaky commented Jul 24, 2021

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

@cpytel
Copy link
Member

cpytel commented Jul 26, 2021

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.

@cpytel
Copy link
Member

cpytel commented Mar 28, 2022

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.

cpytel added a commit that referenced this issue Mar 30, 2022
Closes #589 

This adds support for properly installing Homebrew on either Apple Silicon or Intel machines to the correct Homebrew location on macOS.

Also changes to:
* Using `HEAD` instead of `master`, which comes from the Homebrew home page.
* Use the new  `shellenv` recommended by Homebrew post-install next steps.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants