Conversation
On a freshly booted macOS machine the bootstrap aborted with:
==> Checking for `sudo` access (which may request your password)...
Need sudo access on macOS (e.g. the user mhfs needs to be an Administrator)!
error: Homebrew installation failed
The user is an administrator; the message is a red herring. We run the
Homebrew installer with NONINTERACTIVE=1, and its have_sudo_access() adds
`-n` to sudo whenever that variable is set:
elif [[ -n "${NONINTERACTIVE-}" ]]
then
SUDO+=("-n")
so its pre-flight `sudo -l mkdir` check can never prompt. With no cached
sudo timestamp yet, it fails and the installer aborts.
Prime the timestamp ourselves first with a prompt-capable `sudo -v`. The
installer's privileged commands go through execute_sudo, which calls
/usr/bin/sudo without `-n`, so they re-prompt on their own if the
timestamp expires during the Command Line Tools download later in the
run; only the pre-flight check needed priming.
Also drop the "sudo will ask for your password" line that preceded the
installer, since NONINTERACTIVE=1 is exactly what stopped it from
asking. The replacement is printed only when a prompt is really coming.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The failure
Bootstrapping a freshly reformatted macOS 27 laptop aborted immediately:
Why
The account is an administrator — Homebrew's message is a red herring. We
invoke the installer with
NONINTERACTIVE=1, and itshave_sudo_access()reacts to that by adding
-nto sudo:sudo -nfails outright instead of prompting. A machine that has just bootedhas no cached sudo timestamp, so the pre-flight check fails and the installer
aborts. The
==> sudo will ask for your passwordline we printed one lineearlier was wrong for the same reason:
NONINTERACTIVE=1is precisely whatstopped it from asking.
This reproduces on any freshly booted Mac, so it hits every first-run
bootstrap — the exact case this script exists for.
The fix
Prime the sudo timestamp ourselves with a prompt-capable
sudo -vbeforehanding off. Only the pre-flight check needed it: the installer's privileged
commands go through
execute_sudo, which calls/usr/bin/sudowithout-n, so they re-prompt on their own if the timestamp expires during theCommand Line Tools download later in the run.
Details worth a look while reviewing:
prime_sudoopens withsudo -n -v, so a warm timestamp (or a passwordlesssudo rule) short-circuits and we never announce a prompt that will not come.
if sudo -v; thenrather thansudo -v || die, becauseunder
set -euo pipefailthe latter exits on sudo's status before thediediagnosis is ever printed.
the account not being an administrator.
Testing
Not yet verified end to end on a clean macOS install — that is what keeps this
a draft.
bash -npasses; the reasoning above is from Homebrew's currentinstall.sh. Worth a run on a fresh machine, or at leastsudo -kfollowed bythe bootstrap command, before this merges.
🤖 Generated with Claude Code