"sudo: brew: command not found" error when trying to uninstall python3 in Homebrew

blee
New Contributor

I currently have the script to try and uninstall python3 in Homebrew:

 

sudo brew uninstall python3

 

and keep getting the error "sudo: brew: command not found". I've also tried the command

/opt/homebrew/bin/brew uninstall python3

and run into the error "Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all build scripts full access to your system."

I'm certain that Homebrew and python3 (via Homebrew) is installed on the device I'm pushing this script to. Is there another way I should be running uninstall commands for Homebrew? 

3 REPLIES 3

sdagley
Esteemed Contributor II

@blee Have you tried running the script as the logged in user (see https://scriptingosx.com/2020/08/running-a-command-as-another-user/) If you're pushing the script via a policy that doesn't run it in the user context.

blee
New Contributor

Thanks for the suggestion! Unfortunately it leads to the same error of brew not being recognized. Seems like no matter what I try I either run into this error or the 'running Homebrew on root is extremely dangerous error' and Jamf refuses to continue with the script

sdagley
Esteemed Contributor II

Remove the sudo prefix from the uninstall command since you don't want to run it with elevated privileges. Also note that when running a script via a Jamf Pro policy you're already running with raised privileges so you wouldn't need a sudo prefix on any commands in the script unless it is being used to specify a different user context to run the command under.