This is probably GDPR compliant.
First, note that there may actually be no Personal Information collected, even the IP addresses are (supposedly) anonymised by Google and not stored. At least the developers have worked hard in trying so.
Homebrew is collecting anonymous GA analytics by default. User have this information during installation of this package manager. To opt-out you need go to the web page and choise a way to opt-out (set an envrionment variable or run a command).
Thus users are informed of the data collection and are able to easily opt-out. This may not be an explicit consent —depending on the way it appears on the install—, but it may not be needed.
Opting-out will prevent analytics to be sent. I don't know if analytics would be collected anyway and sent collected afterwards you opt-in collecting analytics again.
Looking at their implementation (analytics.rb, analytics.sh), there is not a separate collection step. When one of the events they record happens, it launches a query to Google Analytics (unless disabled by the environment, the configuration variable, or actually not having an internet connection). The event description is not saved anywhere that could be later sent.