Installing and setting up the Google Cloud CLI on macOS

Hey you! I hope you are having a wonderful day πŸ’›

The intention of these words is to document the installation of the Google Cloud CLI on macOS, that for me was an adventure.

While I was working on the installation, I found documentation in various places, as well as responses to problems in other places, and hmmm, I guess this will be another one of those places 🀭

Aaaanyways, the idea is to document what worked for me 🫢🏼 and hopefully it will help another Earthling πŸ’•

Notes

The version of macOS used for the installation is: macOS Monterrey -version 12.6.6 and platform is macOS 64-bit (x86_64). The same worked for macOS Ventura - version 13.4 and platform macOS 64-bit (ARM64, Apple M1 silicon).

First: brew

The Package Manager for macOS that I used is brew.

So, assuming that you are using brew, before you go on with everything, I recommend to run the following:

1
2
3
brew update
brew upgrade
brew cleanup

Second: python

The Google Cloud CLI uses python, and so the version of python installed on your host is very important. What I found is that if the right version of python is not installed and setup in the host, the Network diagnostic will fail. This means that after running the gcloud info --run-diagnostics command, and waiting for Checking network connection...β Ά …, there will be an error message like the following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
ERROR: Reachability Check failed.
    httplib2 cannot reach https://cloudresourcemanager.googleapis.com/v1beta1/projects:
...

    httplib2 cannot reach https://www.googleapis.com/auth/cloud-platform:
...

    httplib2 cannot reach https://cloudresourcemanager.googleapis.com/v1beta1/projects:
...

...

Network connection problems may be due to proxy or firewall settings.

Do you have a network proxy you would like to set in gcloud (Y/n)?

How did I install Python?

First, I had to uninstall almost all the python and pip versions in the macOS host, and only leave the python and pip at /usr/bin/. I also uninstalled pyenv and the python versions that were installed via pyenv.

ℹ️ If you had versions of Python installed with brew make sure that you run brew cleanup after you uninstall them.

Then I installed python 3.9.2. The installation of this version of python, I did it with asdf. You can find the instructions on how to install asdf here.

After asdf was installed, I installed python with:

1
2
3
asdf plugin add python
asdf install python 3.9.2
asdf global python 3.9.2

✨ python 3.9.2 ✨ is the version that magically worked.

To test that you are using this installation python you can run whereis python in your terminal, and make sure that it refers to the path where asdf installed python.

You can also run: python -V and check that output is: Python 3.9.2.

Third: The Google Cloud CLI

Installation

I used the Google Cloud CLI installer instead of the recommended installation, since it provided more interactivity, it did all it needed to do, and well, it worked πŸ˜…:

1
curl https://sdk.cloud.google.com | bash

When prompted if you want to install Python, say n:

1
2
3
Google Cloud CLI works best with Python 3.7 and certain modules.

Python 3.7 installation detected, install recommended modules? (Y/n)?  n`

Diagnostics

After the installation is finished, run:

1
gcloud info --run-diagnostics --verbosity debug

This step, when it worked, it took 1 second to output something like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Checking network connection...done.
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).

Property diagnostic detects issues that may be caused by properties.
Checking hidden properties...done.
Hidden Property Check passed.
Property diagnostic passed (1/1 checks passed).

INFO: Explicit Display.

πŸŽ‰ #Fiesta πŸŽ‰

If the command takes more than 3 minutes to return, there probably will be a problem, and I would recommend to stop and:

  1. Uninstall the Google Cloud CLI.
  2. Restart the host.
  3. Try the Installation again.

Init

After the diagnostics succeed, you can run gcloud init --console-only. This will run the Network diagnostic again, but since we already tested it in the previous step (Diagnostics), it should take less than 5 seconds and output something like the following:

1
2
3
4
Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).

Then you will be asked to log in with your Google account.

Go through the steps, to authorize the Google Cloud CLI to use your Google Account for authentication, select a project, and at the end you will see a message like the following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
Your Google Cloud SDK is configured and ready to use!

* Commands that require authentication will use [email protected] by default
* Commands will reference project `your-project-example` by default
Run `gcloud help config` to learn how to change individual settings

This gcloud configuration is called [your-config-example]. You can create additional configurations if you work with multiple accounts and/or projects.
Run `gcloud topic configurations` to learn more.

Some things to try next:

* Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command.
* Run `gcloud topic --help` to learn about advanced features of the SDK like arg files and output formatting
* Run `gcloud cheat-sheet` to see a roster of go-to `gcloud` commands.

Next, take a look into the gcloud CLI cheat sheet and have fun!

Happy coding, testing, and cloud’ing! ✨