Dealing With -sh: gcloud: command not found after setting up gcloud CLI

Bob Main
2 min readJul 21, 2023

While creating a recent post about setting up Google App Engine, I had to download and install the gcloud CLI, and I kept encountering this error even after attempting to fix it multiple times. There are many different strategies on how to resolve this issue, but here’s what worked for me on my Mac OS, including some potential gotchas:

  1. Open the Mac OS “Terminal” application.
  2. Install the google-cloud-sdk with Homebrew by running this command:
  • brew install --cask google-cloud-sdk
  • If you don’t have Homebrew, you can install it from here: https://brew.sh/
  1. After installing, execute the following commands to source the execution files:
source "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc"
source "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc"

Now, try: cloud info to see if it worked.🤞

⚠️ If you encounter an error like this:

-sh: autoload: command not found
-sh: zmodload: command not found
-sh: ((: $+functions[compdef] : syntax error: operand expected (error token is "$+functions[compdef] ")
-sh: autoload: command not found

Try swapping zsh with bash in the commands, too they both look like this...

source "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.bash.inc"
source "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.bash.inc"

On my machine, it was zsh for the first command and bash for the second. 😅

I hope this helps with this tricky/annoying issue!

--

--

Bob Main

Exploring the wilderness of web development, creating example apps & tutorials, usually weaving some ✨silliness✨ in! Oh, & other random stuff...