-bash: gcloud: command not found on Mac
Asked Answered
M

13

44

I'm following the Quickstart for Mac OS X to install the cloud SDK. Following the steps exactly,

1) python -V returns "Python 2.7.10"

2) Download and extract using ./install.sh the 64bit version of the SDK in google-cloud-sdk returns...

Welcome to the Google Cloud SDK!

To help improve the quality of this product, we collect anonymized usage data
and anonymized stacktraces when crashes are encountered; additional information
is available at <https://cloud.google.com/sdk/usage-statistics>. You may choose
to opt out of this collection now (by choosing 'N' at the below prompt), or at
any time in the future by running the following command:

    gcloud config set disable_usage_reporting true

Do you want to help improve the Google Cloud SDK (Y/n)?  Y


Your current Cloud SDK version is: 170.0.1
The latest available version is: 170.0.1

┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                  Components                                                 │
├───────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬───────────┤
│     Status    │                         Name                         │            ID            │    Size   │
├───────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼───────────┤
│ Not Installed │ App Engine Go Extensions                             │ app-engine-go            │  97.7 MiB │
│ Not Installed │ Cloud Bigtable Command Line Tool                     │ cbt                      │   4.0 MiB │
│ Not Installed │ Cloud Bigtable Emulator                              │ bigtable                 │   3.5 MiB │
│ Not Installed │ Cloud Datalab Command Line Tool                      │ datalab                  │   < 1 MiB │
│ Not Installed │ Cloud Datastore Emulator                             │ cloud-datastore-emulator │  15.4 MiB │
│ Not Installed │ Cloud Datastore Emulator (Legacy)                    │ gcd-emulator             │  38.1 MiB │
│ Not Installed │ Cloud Pub/Sub Emulator                               │ pubsub-emulator          │  33.2 MiB │
│ Not Installed │ Emulator Reverse Proxy                               │ emulator-reverse-proxy   │  14.5 MiB │
│ Not Installed │ Google Container Local Builder                       │ container-builder-local  │   3.7 MiB │
│ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr    │   2.2 MiB │
│ Not Installed │ gcloud Alpha Commands                                │ alpha                    │   < 1 MiB │
│ Not Installed │ gcloud Beta Commands                                 │ beta                     │   < 1 MiB │
│ Not Installed │ gcloud app Java Extensions                           │ app-engine-java          │ 128.1 MiB │
│ Not Installed │ gcloud app PHP Extensions (Mac OS X)                 │ app-engine-php-darwin    │  21.9 MiB │
│ Not Installed │ gcloud app Python Extensions                         │ app-engine-python        │   6.5 MiB │
│ Not Installed │ kubectl                                              │ kubectl                  │  15.9 MiB │
│ Installed     │ BigQuery Command Line Tool                           │ bq                       │   < 1 MiB │
│ Installed     │ Cloud SDK Core Libraries                             │ core                     │   6.7 MiB │
│ Installed     │ Cloud Storage Command Line Tool                      │ gsutil                   │   3.0 MiB │
└───────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴───────────┘
To install or remove components at your current SDK version [170.0.1], run:
  $ gcloud components install COMPONENT_ID
  $ gcloud components remove COMPONENT_ID

To update your SDK installation to the latest version [170.0.1], run:
  $ gcloud components update

==> Source [/Users/shaneoseasnain/Desktop/google-cloud-sdk/completion.bash.inc] in your profile to enable shell command completion for gcloud.
==> Source [/Users/shaneoseasnain/Desktop/google-cloud-sdk/path.bash.inc] in your profile to add the Google Cloud SDK command line tools to your $PATH.

For more information on how to get started, please visit:
  https://cloud.google.com/sdk/docs/quickstarts

3) I've restarted the terminal and run gcloud init from inside google-cloud-sdk. This returns "command not found." If I run ls, I see the following directory structure:

LICENSE               completion.zsh.inc      path.fish.inc
README                deb                     path.zsh.inc
RELEASE_NOTES         install.bat             platform
VERSION               install.sh              properties
bin                   lib                     rpm
completion.bash.inc   path.bash.inc

4) I've tried to run gcloud init inside bin as well, but get the same problem, command not found.

The only other suggestions I can see from the install guide are "enable command-completion in your bash shell, and/or enable usage reporting." I'm not sure how to do this but command completion and reporting don't look like they should be related to this problem. There is a lot written about command not found but they relate to other problems where, for example, gcloud has stopped working after a while or problems in older versions. Has anyone a tip how to get the cloud sdk working?

Thanks

Muzzy answered 10/9, 2017 at 18:41 Comment(0)
S
105

I had the same issue. A lazy and quick fix for this is to just run:

brew install --cask google-cloud-sdk

Found by googling.

Sherrellsherrer answered 21/11, 2017 at 10:26 Comment(7)
did not fix it for meEmotionalize
Don't know if this broke anything else but gcloud is working again. :)Turoff
This doesn't address what is likely a path issue and it's possible to replicate this issue using that command. It would be helpful to know if you added the path variable to your profile or if you noticed that it was added when running this command.Matteson
After brew install, I found gcloud here: /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/binGoldagoldarina
thank u. such a shame this is not in the official docsKangaroo
formulae.brew.sh/cask/google-cloud-sdkFriedrick
This solution is so simple - why isn't it in the official google docs? cloud.google.com/sdk/docs/installAmygdaline
C
32

For MAC OS - Use Homebrew

brew install --cask google-cloud-sdk

and then use

 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"
Cichlid answered 24/3, 2021 at 23:51 Comment(2)
I have found the following issue when I run source "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc" -bash: autoload: command not found -bash: zmodload: command not found -bash: ((: $+functions[compdef] : syntax error: operand expected (error token is "$+functions[compdef] ") -bash: autoload: command not foundAmadaamadas
@nawazanjum you probably are having problems because the instructions above are for zsh and you're running bash. you can try swapping out zsh for bash in the paths above. after installing through brew, it prints: ``` for bash users source "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.bash.inc" source "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.bash.inc" ```Gilemette
S
12

The gcloud executable lives in google-cloud-sdk/bin–to run gcloud. You'll need to either:

  1. Add this directory to your $PATH. In particular, adding the line source /Users/shaneoseasnain/Desktop/google-cloud-sdk/path.bash.inc to your .bash_profile file (more detail on what this file does and how to pick one) will do the trick.
  2. Specify the full path to the gcloud executable when you run it. In your case, this is /Users/shaneoseasnain/Desktop/google-cloud-sdk/bin/gcloud. So for example:

    $ /Users/shaneoseasnain/Desktop/google-cloud-sdk/bin/gcloud init
    

The pertinent part of the quickstart (emphasis added):

Run the install script to add Cloud SDK tools to your path, enable command-completion in your bash shell, and/or enable usage reporting:

As to why the install script didn't work, I can't say. Please file an issue and we'll investigate.

Salient answered 10/9, 2017 at 22:11 Comment(0)
B
9

Here's on macOS. I had the same problem. I got

gcloud: command not found

After running brew install --cask google-cloud-sdk, I found that I have to install it manually.

  • First, you will find install.sh under directory google-cloud-sdk, and you will run .../google-cloud-sdk/install.sh under the terminal. For my case, the file is under /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk

  • Second, run /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/install.sh

  • Third, there will be a message guide you to relaunch your terminal owing to your bash file or zsh file updated.

  • Fourth, gcloud -v to test if gcloud-cli work normally after you launch a new terminal.

Barthol answered 8/2, 2021 at 5:15 Comment(1)
I only did the 2nd step /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/install.sh and followed the prompts and it workedJohnnyjohnnycake
O
5

In short:

emacs -nw ~/.zshrc

And add following line at the beginning:

# The next line updates PATH for the Google Cloud SDK.
source '/home/lesaint/GOOGLE_CLOUD/google-cloud-sdk/path.zsh.inc'

# The next lines enables bash completion in Zsh for gcloud. 
autoload -U compinit compdef
compinit
source '/home/lesaint/GOOGLE_CLOUD/google-cloud-sdk/completion.zsh.inc'

The solution proposed by following article works for me:

http://www.javatronic.fr/tips/2014/10/17/installing_google_cloud_sdk_on_ubuntu_with_oh-my-zsh.html

Oshinski answered 13/3, 2020 at 11:59 Comment(2)
Thanks a lot just this worked for me. I'm on macOS CatalinaWarnke
I found this related comment helpfulTearoom
B
4

TL;DR - follow the Interactive installer section of Installing Cloud SDK and the SDK will install correctly.

However, there is a real issue here which I believe is related to missing environment variables:

At first, I followed Quickstart for Mac OS X as well in order to install the Google Cloud SDK for the 'Mac OS X (x86_64) Platform'. This reproduced the exact same results as Shane outlined in his question above. Here are some more details:

  • Clean install of macOS Sierra 10.12.6 (latest) on a 2017 MacBook Pro.
  • Google Cloud SDK version 173.0.0. Specifically: google-cloud-sdk-173.0.0-darwin-x86_64.tar.gz which is the latest at the time of this writing and the one pointed to by the quickstart guide.

I was able to further pinpoint the problem in step 4 of the 'Before you begin' section of Quick Start for Mac OS X:

Set up the Cloud SDK for use. If you're having trouble getting the gcloud command to work, ensure your $PATH is defined appropriately. Run the install script to add Cloud SDK tools to your path, enable command-completion in your bash shell, and/or enable usage reporting:

./google-cloud-sdk/install.sh

'install.sh' invokes 'install.py' which at some point calls isatty() in order to find out whether the installation process was run from the shell which means it should be interactive and prompt the user for some information. For some reason, isatty() returns False instead of True! This causes to script to fall through non-interactively and - because 'install.sh' was invoked without arguments - Fail.

Bryozoan answered 30/9, 2017 at 9:10 Comment(0)
H
4

The following worked for me:

  • I moved the installer unzipped package to the ~ directory.
  • And then after running ./google-cloud-sdk/install.sh
  • I restarted the terminal again and ran 'gcloud init' and it worked.
Heliocentric answered 12/10, 2017 at 1:28 Comment(1)
Forgot to restart the terminal.Failsafe
A
2

Sometimes, after installation, you need just restart your terminal. that's it :)

take a look at here: Quickstart for macOS

Alexanderalexandr answered 1/6, 2019 at 0:42 Comment(0)
D
0

for me that was the fix:

mkdir -p $sdk_dir/.install/

tl;dr;

It seems that the python library is locating the sdk_root by searching for an .install directory. See the config.py and the definition of CLOUDSDK_STATE_DIR

Donau answered 1/9, 2019 at 7:43 Comment(0)
C
0

It seems like your google-cloud-sdk/bin does not appear in PATH.

copy your current PATH from:

echo $PATH

Now add your google-cloud-sdk/bin absolute path to PATH, don't forget to add a colon - ':', before you add your new path, it should be something like this:

PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/Users/user/google-cloud-sdk/bin
Criner answered 2/3, 2022 at 12:49 Comment(0)
G
0

I ran the install and init command from the folder, i kept downloaded SDK. One it installed and initialized, i ran the command with folder name and it worked after that. i ran below command from directory where i kept SDK- ./google-cloud-sdk/bin/gcloud

Garek answered 15/7, 2022 at 1:46 Comment(0)
C
0

Highly recommend to unpack/unzip *.tar.gz Google Cloud SDK installer inside Finder.app

When I used the same Archive Utility inside Forklift.app (my main macOS file manager) install.sh produced several errors, despite google-cloud-sdk folder looks the same at the first glance.

Companionate answered 17/9, 2023 at 17:34 Comment(0)
P
-2

Follow these steps:

  1. Press Command+Space and type Terminal and press enter/return key.

  2. Run in Terminal app:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null ; brew install caskroom/cask/brew-cask 2> /dev/null

If the screen prompts you to enter a password, please enter your Mac's user password to continue. When you type the password, it won't be displayed on the screen, but the system would accept it. So just type your password and press ENTER/RETURN key. Then wait for the command to finish.

  1. Run
brew cask install google-cloud-sdk

Reference:

http://macappstore.org/google-cloud-sdk/

Pibroch answered 17/9, 2018 at 15:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.