The instructions at https://brew.sh/ are extremely dangerous! Here is how to
install homebrew
properly.
NOTE: we assume your homebrew path is:
~/Workspace/Hub/brew
Code Link to heading
-
Clone the repository:
git clone https://github.com/Homebrew/brew.git ~/Workspace/Hub/brew cd ~/Workspace/Hub/brew
-
Review the code carefully!
-
Check the commit sha matches the one from the last commit on the repository website:
git rev-parse HEAD
-
Now you have a secure copy of the repository and you can automate the process.
Automation Link to heading
IMPORTANT: on Linux,
homebrew
adds itself in the front of your PATH, so any package installed byhomebrew
will have higher priority than your system packages. This includes critical ones likepkg-config
, which means you will start seeing errors when compiling, unless you duplicate all your compile time or runtime libraries by installling them with thebrew
command.To avoid this, we will only enable homebrew manually in the shell we need it.
-
Add the following setup to your
~/.bash_profile
to allow enablinghomebrew
on demand:#------------------------------------------------------------------------------- # Homebrew #------------------------------------------------------------------------------- export HOMEBREW_NO_ANALYTICS=1 function Enable { case "$1" in "brew") eval "$(~/Workspace/Hub/brew/bin/brew shellenv)" shift ;; *) return ;; esac }
-
Set up your current shell by executing this in your homebrew directory:
eval `bin/brew shellenv`
-
Any future shells can have homebrew by executing this command:
Enable brew
-
Ensure analytics are disabled at the command level:
brew analytics off
-
Update everything:
brew update --force brew upgrade
Usage Link to heading
Remember, you need to enable it first before running any commands:
Enable brew
Now you can install any package with a clear conscience.
brew install hello