Geekflare is supported by our audience. We may earn affiliate commissions from buying links on this site.
In Cloud Computing Last updated: May 20, 2022
Share on:
Invicti Web Application Security Scanner – the only solution that delivers automatic verification of vulnerabilities with Proof-Based Scanning™.

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.

gcloud-cloud-shell

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.

gcloud-cloud-shell-web

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:Temp\GoogleCloudSDKInstaller.exe")

& $env:Temp\GoogleCloudSDKInstaller.exe

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

google-cloud-sdk-windows-installer

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.

google-cloud-sdk-windows-installer-7

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.

google-cloud-sdk-windows

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:

IDNameDescription
gcloudDefault gcloud CLI CommandsTool 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.
bqBigQuery Command-Line ToolTool for working with data in Google BigQuery
gsutilCloud Storage Command-Line ToolTool for performing tasks related to Google Cloud Storage.
coreCloud SDK Core LibrariesLibraries 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.

PlatformPackageSizeSHA256 Checksum
macOS 64-bit(x86_64)google-cloud-sdk-346.0.0-darwin-x86_64.tar.gz86.5 MB632164280208c050f015c9d04fa805c05478e80518a0fe667b413df55ab926ee
macOS 64-bit(arm64)google-cloud-sdk-346.0.0-darwin-arm.tar.gz86.4 MB707948f45c8cc01012a92e3aff8af3701a89777bccdeec905310f70951c75bdb
macOS 64-bit with bundled Python(x86_64)google-cloud-sdk-346.0.0-darwin-x86_64-bundled-python.tar.gz128.4 MBa31d67193ca21bf6943c275c633f3f5bf11c8526f47808f13a3c516df2e7aae3
macOS 32-bit(x86)google-cloud-sdk-346.0.0-darwin-x86.tar.gz90.3 MB85493c0c5aba8fce9f8e7d1886bc0916db44bd0847cbf862cf87435fc8d729ff

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<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:

$ 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.

Learn how to check and clear the ARP cache in Windows, Linux and Mac.

  • Abhishek Nair
    Author
Thanks to our Sponsors
More great readings on Cloud Computing
Power Your Business
Some of the tools and services to help your business grow.
  • Invicti uses the Proof-Based Scanning™ to automatically verify the identified vulnerabilities and generate actionable results within just hours.
    Try Invicti
  • Web scraping, residential proxy, proxy manager, web unlocker, search engine crawler, and all you need to collect web data.
    Try Brightdata
  • Monday.com is an all-in-one work OS to help you manage projects, tasks, work, sales, CRM, operations, workflows, and more.
    Try Monday
  • Intruder is an online vulnerability scanner that finds cyber security weaknesses in your infrastructure, to avoid costly data breaches.
    Try Intruder