Here's a quick and dirty way to opt out for BASH and ZSH users for easy copy/pasting.
BASH:
cat <<EOF >> .bashrc
# Opt out of Homebrew analytics
export HOMEBREW_NO_ANALYTICS=1
if [[ -e "$HOME/.homebrew_analytics_user_uuid" ]]; then
rm -f "$HOME/.homebrew_analytics_user_uuid"
fi
EOF
ZSH:
cat <<EOF >> .zshrc
# Opt out of Homebrew analytics
export HOMEBREW_NO_ANALYTICS=1
if [[ -e "$HOME/.homebrew_analytics_user_uuid" ]]; then
rm -f "$HOME/.homebrew_analytics_user_uuid"
fi
EOF
Good call. I was mainly using `-f` to suppress the prompt about deleting the file, but you're correct, it's unnecessary to have the if statement in this case.
You don’t need to remove that file; the whole point of this env variable is that it stops Homebrew from sending any data. It won’t even be created if that variable is set.
That's only true if the variable is set before the first instance when data would have been sent, otherwise the file will exist (as it did on my system).
BASH:
ZSH: Cheers.