Homebrew installer in Bash is released!

itchyny
2 min readMar 4, 2020

The installer of Homebrew was written in Ruby for years. Here’s the legacy installation command.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Homebrew largely depends on Ruby and it’s a good choice. The DSL allows us to create the formula easily. However, using Ruby for installer was a problem. It should run successfully on the clean macOS and using Ruby for this kind of script is a risk.

  • macOS will not include scripting languages like Ruby and Python by default in the future (49764202). It is too heavy to install Ruby before running the installation script.
  • There’s no task which should be done in Ruby. Roughly speaking, it only executes chmod, chown and git clone so shell script is more suitable.

The core members of Homebrew have been discussed on this topic for months (Port installer to Bash #217), but nobody seems to work on this. In a cold day in January, I started to rewrite the installer to Bash. It took 5 hours to complete the first porting and soon I submitted the pull request.

The original Ruby script is just 381 LOC, but any command should not be dropped while porting. I firstly git mv -ed the script and write exit at the top, and then migrated to shell script by moving the exit step by step. The CI is not enough to enter all the conditional branches (for example, warning for old versions of macOS), I carefully checked the outputs of each commands in conditions not to change the behavior.

Recently the pull request was finally merged and the official homepage was updated. This is the new installation command.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

I rephrase that the problem existed in the installer which should run successfully on the clean macOS. Homebrew still relies on Ruby, and it’s totally fine. Writing a formula is very easy due to the DSL.

The skill of writing a Bash script is not important these days. It’s better to choose other languages in most situations. But sometimes there’re rare cases that Bash scripting is appropriate. Also, the installer for Linux was also unified (Linux support for the installer).

Note that using Bash on macOS is also a risk due to the license issues. But rewriting to the login shell (currently, zsh) is much easier than rewriting a Ruby script to a shell script.

I’m honored to be involved in the installer, and love the Homebrew community. Thank you!

--

--