Skip to content

Commit cd1979f

Browse files
committed
added uninstall and README
1 parent 5e84247 commit cd1979f

File tree

3 files changed

+154
-22
lines changed

3 files changed

+154
-22
lines changed

README.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,56 @@
1-
# M1_native_homebrew
2-
Install homebrew in native mode on Apple MacOS Arm (M1)
1+
# Using CLI/Terminal on Apple M1 (MacOS Big Sur)
2+
3+
## `install_homebrew_native.sh`
4+
5+
* install Homebrew in native mode (without Rosetta 2) on a fresh Apple M1 Arm computer (MacOS Big Sur)
6+
* run as: `curl -s https://raw.githubusercontent.com/pforret/macos_m1_cli/main/install_homebrew_native.sh | bash`
7+
8+
## Using native Homebrew
9+
10+
* as long as Homebrew does not officially support Apple M1 ARM architecture,
11+
you will get the following warning every time you try to `brew install` a package
12+
13+
14+
Warning: You are running macOS on a arm64 CPU architecture.
15+
We do not provide support for this (yet).
16+
Reinstall Homebrew under Rosetta 2 until we support it.
17+
You will encounter build failures with some formulae.
18+
Please create pull requests instead of asking for help on Homebrew's GitHub,
19+
Twitter or any other official channels. You are responsible for resolving
20+
any issues you experience while you are running this
21+
unsupported configuration.
22+
23+
* you can however install the package by using `brew1 install`,
24+
which is short for `brew --build-from-source install`
25+
* the installation will probably work, but it's not guaranteed.
26+
You are an early adopter, doing bleeding edge stuff, not for the faint of heart.
27+
28+
## `uninstall_homebrew_native.sh`
29+
30+
* if you prefer running in 'Rosetta 2' mode, you can uninstall the native mode Homebrew.
31+
* run as: `curl -s https://raw.githubusercontent.com/pforret/macos_m1_cli/main/uninstall_homebrew_native.sh | bash`
32+
33+
## My Homebrew configuration
34+
35+
This is my config (on Mac Mini M1):
36+
37+
HOMEBREW_VERSION: 2.6.2-91-g9db324a
38+
ORIGIN: https://github.com/Homebrew/brew
39+
HEAD: 9db324ab7a28446debcb407859c9ac184594a772
40+
Last commit: 6 hours ago
41+
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
42+
Core tap HEAD: 72f2ab4cf6ab6cf12044f083c0e062876357bf04
43+
Core tap last commit: 2 hours ago
44+
Core tap branch: master
45+
HOMEBREW_PREFIX: /opt/homebrew
46+
HOMEBREW_CASK_OPTS: []
47+
HOMEBREW_MAKE_JOBS: 8
48+
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
49+
CPU: octa-core 64-bit arm_firestorm_icestorm
50+
Clang: 12.0 build 1200
51+
Git: 2.24.3 => /Library/Developer/CommandLineTools/usr/bin/git
52+
Curl: 7.64.1 => /usr/bin/curl
53+
macOS: 11.0-arm64
54+
CLT: 12.3.0.0.1.1607026830
55+
Xcode: N/A
56+
Rosetta 2: false

install_homebrew_native.sh

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,73 @@
11
#!/bin/bash
2+
set -uo pipefail
3+
echo "### $0 from pforret/macos_m1_cli"
4+
5+
die(){
6+
echo "$1" >&2
7+
tput bel
8+
echo "Quitting script!" >&2
9+
exit 1
10+
}
211

312
if [[ -x "/opt/homebrew/bin/brew" ]] ; then
4-
echo "Homebrew is already installed at [/opt/homebrew/bin], quitting script!" >&2
5-
/opt/homebrew/bin/brew update
13+
/opt/homebrew/bin/brew update > /dev/null
614
/opt/homebrew/bin/brew config | grep VERSION
7-
exit 1
15+
die "Homebrew is already installed at [/opt/homebrew/bin]"
816
fi
917

18+
# Sanity check, only run on MacOs in native mode
19+
[[ $(uname) == "Darwin" ]] || die "This script should only be run on a MacOS machine"
20+
[[ $(uname -m) == "arm64" ]] || die "This script should only be run in native mode, not with Rosetta 2"
21+
[[ $UID -eq 0 ]] && die "You should not be root to run this script"
22+
1023
# first run git to initiate download of developer tools
11-
echo "* Check if git is installed ..."
12-
git version || echo "If you get a popup asking to install 'developer tools', please say yes" >&2
24+
echo "* If you get a MacOS popup asking to install 'developer tools', please confirm"
25+
git version
1326

1427
echo "* Create a folder for Homebrew ..."
1528
cd /opt && sudo mkdir homebrew
16-
if [[ ! -f "/opt/homebrew" ]] ; then
17-
echo "Folder [/opt/homebrew] could not be created, quitting script!" >&2
18-
exit 1
19-
fi
29+
[[ -d "/opt/homebrew" ]] || die "Folder [/opt/homebrew] could not be created"
30+
2031
sudo chown -R "$(whoami)" /opt/homebrew
2132

22-
echo "* Download and install Homebrew ..."
33+
echo "* Download and install Homebrew from Github ..."
2334
# cf https://docs.brew.sh/Installation.
2435
curl -L "https://github.com/Homebrew/brew/tarball/master" | tar xz --strip 1 -C homebrew
2536

26-
if [[ ! -x "/opt/homebrew/bin/brew" ]] ; then
27-
echo "Executable [/opt/homebrew/bin/brew] not found, quitting script!" >&2
28-
exit 1
29-
fi
37+
[[ -x "/opt/homebrew/bin/brew" ]] || die "Executable [/opt/homebrew/bin/brew] not found"
38+
39+
startup_config(){
40+
comment="#M1HBnat"
41+
echo "## /opt/homebrew is homebrew for native Apple ARM M1 mode $comment"
42+
echo "export PATH=/opt/homebrew/bin:\$PATH $comment"
43+
echo "alias brew1 \"brew --build-from-source\" $comment"
44+
}
3045

3146
case $(basename "$SHELL") in
3247
zsh)
3348
echo "* Adding [/opt/homebrew/bin] to your zsh startup config path"
34-
echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc
49+
startup_config >> ~/.zshrc
3550
;;
51+
3652
bash)
3753
echo "* Adding [/opt/homebrew/bin] to your bash startup config path"
38-
echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.bashrc
54+
startup_config >> ~/.bashrc
3955
;;
56+
4057
*)
41-
echo "Please add [/opt/homebrew/bin] to your path, could not be done automatically" >&2
58+
echo "Add the following to your shell startup script, could not be done automatically" >&2
59+
echo "#####"
60+
startup_config
61+
echo "#####"
4262
esac
4363

4464
echo "* Running brew a first time to trigger compilation"
45-
/opt/homebrew/bin/brewbrew install --build-from-source -q awk 2> /dev/null
65+
/opt/homebrew/bin/brew install --build-from-source -q awk 2> /dev/null
4666

4767
echo "* Homebrew was installed as native binary. Version will be > 2.6"
4868
/opt/homebrew/bin/brew config | grep VERSION
69+
echo "* Installation using 'brew install' will give a warning as long as Homebrew is not yet officially released for M1"
70+
echo "* You can use 'brew1 install' to always build from source and skip that warning"
71+
echo "* You might get build errors, but remember: you are now doing bleeding edge CLI Terminal!"
4972

50-
echo "* Rosetta 2 should be 'false'"
51-
/opt/homebrew/bin/brew config | grep Rosetta
73+
echo "> Close this Terminal and start a new one to make sure brew is in the path"

uninstall_homebrew_native.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
set -uo pipefail
3+
echo "### $0 from pforret/macos_m1_cli"
4+
5+
die(){
6+
echo "$1" >&2
7+
tput bel
8+
echo "Quitting script!" >&2
9+
exit 1
10+
}
11+
12+
[[ -x "/opt/homebrew/bin/brew" ]] || die "Homebrew is not installed on [/opt/homebrew]"
13+
14+
# Sanity check, only run on MacOs in native mode
15+
[[ $(uname) == "Darwin" ]] || die "This script should only be run on a MacOS machine"
16+
[[ $(uname -m) == "arm64" ]] || die "This script should only be run in native mode, not with Rosetta 2"
17+
[[ $UID -eq 0 ]] && die "You should not be root to run this script"
18+
19+
echo "* Create a folder for Homebrew ..."
20+
cd /opt && sudo mkdir homebrew
21+
[[ -d "/opt/homebrew" ]] || die "Folder [/opt/homebrew] could not be created"
22+
23+
sudo chown -R "$(whoami)" /opt/homebrew
24+
25+
echo "* Download and install Homebrew from Github ..."
26+
# cf https://docs.brew.sh/Installation.
27+
curl -L "https://github.com/Homebrew/brew/tarball/master" | tar xz --strip 1 -C homebrew
28+
29+
[[ -x "/opt/homebrew/bin/brew" ]] || die "Executable [/opt/homebrew/bin/brew] not found"
30+
31+
remove_from_config(){
32+
comment="#M1HBnat"
33+
conffile="$1"
34+
tempfile="$1.tmp"
35+
< "$conffile" grep -v "$comment" > "$tempfile"
36+
[[ -f "$tempfile" ]] && [[ $(< "$tempfile" wc -l) -gt 0 ]] && mv "$conffile" "$conffile.bak" && mv "$tempfile" "$conffile"
37+
}
38+
39+
case $(basename "$SHELL") in
40+
zsh)
41+
echo "* Removing [/opt/homebrew/bin] from your zsh startup config path"
42+
remove_from_config ~/.zshrc
43+
;;
44+
45+
bash)
46+
echo "* Removing [/opt/homebrew/bin] from your bash startup config path"
47+
remove_from_config ~/.bashrc
48+
;;
49+
50+
*)
51+
echo "* Remove all lines mentioning /opt/homebrew from your startup scripts: " >&2
52+
sleep 1
53+
esac
54+
55+
echo "* Deleting Homebrew from [/opt/homebrew]"
56+
sudo rm -fr /opt/homebrew

0 commit comments

Comments
 (0)