Install Google Cloud SDK using Homebrew on Mac

Managing GCP through CLI

Jansutris Apriten Purba
3 min readSep 1, 2021
G-cloud CLI

Before Starting:

  1. Create one google cloud Platform Project.
  2. Cloud SDK requires Python. Supported versions are 3.5 to 3.7, and 2.7.9 or higher. To check the Python version installed on your system:
python -V

This is a short and quick guide to install and configure Google Cloud SDK using Homebrew. If you are not using Homebrew to manage your packages, then you can follow the official guide to setup directly into Mac.

Step 1: Prepare Homebrew

If you don’t have Homebrew, then you need to install it first. Open your terminal of choice then type following command to get Homebrew for your Mac.

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Verify installation by:

$ brew --version
Homebrew 2.2.6
Homebrew/homebrew-core (git revision ae7c1; last commit 2020-02-22)
Homebrew/homebrew-cask (git revision 2eac7b; last commit 2020-02-23)

You might want to install the cask plugin if you’re using old Homebrew version, which extends Homebrew functionalities to install more stuffs on Mac machine. Use following command to get it.

$ brew tap caskroom/cask

Step 2: Install Google Cloud SDK

Now, we get the CLI for Google Cloud, type following command:

$ brew cask install google-cloud-sdk

and then add this pseudo-code in ~/.zshrc config file:

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"

After installation, you can verify the installation by issuing:

$ gcloud version
Google Cloud SDK 281.0.0
bq 2.0.53
core 2020.02.14
gsutil 4.47

Step 3: Authenticate Google Cloud Developer account

Finally step is to authenticate to your Google Cloud Developer account to manage.

$ gcloud auth login

It will display an URL, you open it via browser, and login with the associated account on Google and allow the SDK with listed permissions.

Configuring the SDK

1. Use the below-mentioned command to authorizing the SDK tools to access Google Cloud Platform using your user account credentials and setting up the default SDK configuration.

gcloud init

Note: if you get an error that gcloud command not found try checking your bash_profile where you have installed the SDK tools.

2. Grant access to your google account associated with GCP.

To continue, you must log in. Would you like to log in (Y/n)? Y

3. Now select the project from the available project which you want to get assigned to gcloud SDK.

Pick cloud project to use:
[1] [my-project-1]
[2] [my-project-2]
...
Please enter your numeric choice:

If you only have one project, gcloud init selects it for you.

4. Choose the zone of your project but if you have google compute engine API are enabled they automatically take the compute engine zone.

Which compute zone would you like to use as project default?
[1] [asia-east1-a]
[2] [asia-east1-b]
...
[14] Do not use default zone
Please enter your numeric choice:

5. Now the gcloud init will confirm to that setup steps successfully:

gcloud has now been configured!
You can use [gcloud config] to change more gcloud settings.
Your active configuration is: [default]

Now the gcloud SDK tools are successfully installed on your macOS and you can use to manage all the resources from CLI only you can check the info of current configuration by:

gcloud info

To view information about gcloud commands and other topics from the command line:

gcloud help

It will going to give you all the available commands that you can use to manage the resources of your GCP.

Then it’s done. No complication to install and configure Google Cloud SDK using Homebrew. You can start to manage the cloud now!

Some references you might want to take a look at:

--

--