gcloud is the primary CLI tool to work with Google Cloud resources.

Using CLI tools offers automation options with easy-to-build scripts, which otherwise is not possible if you rely exclusively on the cloud provider’s web interface only.

With gcloud CLI, you can create, modify and delete various types of Google Cloud resources like Google Compute Engine virtual machines, Google Cloud SQL instances, Google Kubernetes Engine clusters, Google Cloud DNS, and Google Cloud Deployment Manager.

Further, it can be used to deploy App Engine applications, manage authentication to cloud resources, customize resource configuration, and various such administrative tasks.

Google Cloud gives you the option to open a shell with gcloud CLI already available and configured to use with your cloud account.

What is gcloud and How to install on Windows, macOS and Linux? Cloud Computing GCP

Click on the shell icon on the top right telling Activate Cloud Shell to access gcloud CLI from a web browser. This will open a shell window at the bottom.

What is gcloud and How to install on Windows, macOS and Linux? Cloud Computing GCP

But if you want to use gcloud to manage your Google Cloud account directly from your system, you must install it first. In this article, we’ll be covering the installation of gcloud CLI on Windows, macOS, and Linux as part of the Google Cloud SDK setup.

Windows

Windows installation binaries are available to set up gcloud SDK, which includes gcloud CLI. You can download the latest package of Cloud SDK installer here. Or else you can open a PowerShell terminal and input the below commands to download the installer and launch it.

(New-Object Net.WebClient).DownloadFile("https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe", "$env:TempGoogleCloudSDKInstaller.exe")

& $env:TempGoogleCloudSDKInstaller.exe

Once launched, follow the on-screen wizard to finish the installation.

What is gcloud and How to install on Windows, macOS and Linux? Cloud Computing GCP

Cloud SDK requires Python, and the dependencies are bundled with the installer. So you can use default options at every step of the installation wizard unless you have a specific requirement to change installation components or location etc.

What is gcloud and How to install on Windows, macOS and Linux? Cloud Computing GCP

You’ll be finally prompted with options to create useful shortcuts and initialize gcloud to configure it to use it with your Google Cloud account. Simply follow on-screen instructions, which will launch a login screen using the default browser. Once logged in, the shell will ask you to select the default project and region to use with gcloud CLI. Once ready, you can run gcloud commands from Windows Command Prompt.

What is gcloud and How to install on Windows, macOS and Linux? Cloud Computing GCP

Default SDK install doesn’t include some extra components like App Engine extensions, which you can separately install using Cloud SDK component manager. The components include by default with SDK are:

ID Name Description
gcloud Default gcloud CLI Commands Tool for interacting with Google Cloud. Only commands at the General Availability and Preview release levels are installed with this component. You must separately install the gcloud alpha Commands and/or gcloud beta Commands components if you want to use commands at other release levels.
bq BigQuery Command-Line Tool Tool for working with data in Google BigQuery
gsutil Cloud Storage Command-Line Tool Tool for performing tasks related to Google Cloud Storage.
core Cloud SDK Core Libraries Libraries are used internally by the SDK tools.

macOS

gcloud SDK requires Python to work and should be installed on your macOS for gcloud CLI to function.

Modern macOS should include the required version of Python by default. There’s an option to use Cloud SDK bundled with Python 3 to install the required dependencies along with gcloud CLI. You can check the version of python on your macOS by opening a terminal and running python -V

 $ python -V

Then run uname -m and determine the machine hardware of your system.

$ uname -m

Based on your machine architecture, choose the right package to download. At the time of writing this article, gcloud 346.x version is available.

You can then simply extract the compressed TAR archive to your preferred location, likely somewhere inside your home directory. To add the cloud SDK tools to your PATH and command completion for your shell, run the below script from the root of the extracted directory:

$ ./google-cloud-sdk/install.sh

Proceed to initialize the SDK using:

$ ./google-cloud-sdk/bin/gcloud init

Additional components can be installed for your cloud SDK using component manager.

RHEL/CentOS

On an RHEL/Fedora/CentOS-based system, you can install from the Google Cloud SDK’s yum repositories.

It is available in package format for installation on Red Hat Enterprise Linux 7, Red Hat Enterprise Linux 8, Fedora 33, and CentOS 7 and 8 systems. This package contains the gcloudgcloud alphagcloud betagsutil, and bq commands only. It does not include kubectl or the App Engine extensions required to deploy an application using gcloud commands, which can be installed separately.

To install using dnf utility, first, add the Cloud SDK repo by running below in a terminal:

$ sudo tee -a /etc/yum.repos.d/google-cloud-sdk.repo << EOM
[google-cloud-sdk]
name=Google Cloud SDK
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
       https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOM

Then install the Cloud SDK using:

$ sudo dnf install google-cloud-sdk

Below are the additional components of Cloud SDK that can be optionally installed based on need:

  • google-cloud-sdk-app-engine-python
  • google-cloud-sdk-app-engine-python-extras
  • google-cloud-sdk-app-engine-java
  • google-cloud-sdk-app-engine-go
  • google-cloud-sdk-bigtable-emulator
  • google-cloud-sdk-cbt
  • google-cloud-sdk-cloud-build-local
  • google-cloud-sdk-datalab
  • google-cloud-sdk-datastore-emulator
  • google-cloud-sdk-firestore-emulator
  • google-cloud-sdk-pubsub-emulator
  • kubectl

As an example, to install google-cloud-sdk-app-engine-java, use:

$ sudo dnf install google-cloud-sdk-app-engine-java

To initialize and configure gcloud with your Google Cloud account, run the below command and follow the instructions:

$ gcloud init

Debian/Ubuntu

Similarly, for Debian and Ubuntu-based systems, Cloud SDK is available in package format as well. Again, this package contains the gcloudgcloud alphagcloud betagsutil, and bq commands only. It does not include kubectl or the App Engine extensions required to deploy an application using gcloud commands. If you want these components, you must install them separately.

As a prerequisite for Debian/Ubuntu installations, ensure that the Ubuntu release you’re on has not reached end-of-life. If you’re on Debian, make sure you’re on Debian’s stable release from Wheezy forward.

To proceed with Cloud SDK installation, first, add the distribution URI as a package source:

$ echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list

Make sure you’ve the below packages installed:

$ sudo apt-get install apt-transport-https ca-certificates gnupg

Import the Google Cloud public key:

$ curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -

Finally, update and install the Cloud SDK:

$ sudo apt-get update && sudo apt-get install google-cloud-sdk

Any of the below components can be optionally installed over and above the base Cloud SDK setup:

  • google-cloud-sdk-app-engine-python
  • google-cloud-sdk-app-engine-python-extras
  • google-cloud-sdk-app-engine-java
  • google-cloud-sdk-app-engine-go
  • google-cloud-sdk-bigtable-emulator
  • google-cloud-sdk-cbt
  • google-cloud-sdk-cloud-build-local
  • google-cloud-sdk-datalab
  • google-cloud-sdk-datastore-emulator
  • google-cloud-sdk-firestore-emulator
  • google-cloud-sdk-pubsub-emulator
  • kubectl

To do that, install the required component using below apt-get command:

$ sudo apt-get install google-cloud-sdk-app-engine-java

Now you’re ready to initialize gcloud using:

$ gcloud init

Follow the on-screen instructions to connect your Google Cloud account and configure the default options.

Summary

Like AWS CLI, Google Cloud offers a CLI tool to manage the Google Cloud infrastructure. This helps in doing some repetitive tasks faster and offers an opportunity to write scripts and automation tools, paving the way towards Infrastructure-as-Code (IaC).

To learn more about the Google Cloud CLI tool, i.e., gcloud, refer to its documentation page and cheat sheet.