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.
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.
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 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.
Once launched, follow the on-screen wizard to finish the installation.
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.
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.
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:
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.
Tool for performing tasks related to Google Cloud Storage.
Cloud SDK Core Libraries
Libraries are used internally by the SDK tools.
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:
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 gcloud, gcloud alpha, gcloud beta, gsutil, 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
Below are the additional components of Cloud SDK that can be optionally installed based on need:
As an example, to install google<span class="pun">-</span><span class="pln">cloud</span><span class="pun">-</span><span class="pln">sdk</span><span class="pun">-</span><span class="pln">app</span><span class="pun">-</span><span class="pln">engine</span><span class="pun">-</span>java, use:
To initialize and configure gcloud with your Google Cloud account, run the below command and follow the instructions:
$ gcloud init
Similarly, for Debian and Ubuntu-based systems, Cloud SDK is available in package format as well. Again, this package contains the gcloud, gcloud alpha, gcloud beta, gsutil, 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
Follow the on-screen instructions to connect your Google Cloud account and configure the default options.
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).