What is gcloud CLI and How to Install on Windows, macOS and Linux

Hello there! Are you just getting started with Google Cloud? As you begin deploying applications and infrastructure on this platform, it is important to understand what client access tools are available and how to get them installed on your desktops and laptops.

In this comprehensive guide, I will explain what gcloud is, why the CLI tool is useful, and exactly how to get it set up on Windows, macOS and common Linux distributions. By the end, you‘ll be equipped with practical tips to be productive through the command line with Google Cloud!

What is Cloud CLI and Why gcloud?

The cloud has transformed application design, deployment and scaling with infrastructure hosted by providers like Google Cloud Platform (GCP). While early interactions were driven through visual console dashboards, CLI (command line interface) tools emerged to enable automation and DevOps-style agile delivery.

So why use CLIs instead of slick modern GUIs?

Benefits include:

❑ Scripting repetitive tasks instead of tedious point-and-click
❑ Combining functions through code for faster deployments
❑ Infrastructure-as-a-Service foundations for performance
❑ Taking backups, logs through consistent interfaces
❑ Cross-platform support for Linux, macOS and Windows

For Google Cloud specifically, their CLI is called gcloud – a comprehensive set of commands to create, manage, secure and monitor all GCP services through an easy-to-use terminal interface on your desktop or laptop machines.

Overview of gcloud and Google Cloud SDK

The gcloud tool belongs to the Google Cloud SDK suite of products focused on developer productivity. Key components you get out-of-box include:

gcloud – Main CLI for Google Cloud services like Compute Engine, GKE, Cloud Run etc.

gsutil – Storage transfer and sync tool for Cloud Storage buckets

bq – BigData queries against BigQuery data warehouses

core – Shared libraries, authentication, configs

Additionally, extensions can be added for App Engine, Cloud Functions, emulators of Google databases and more.

Why is the gcloud CLI so useful?

While modern GUIs let you manage cloud platforms visually, there are significant advantages in learning gcloud thoroughly:

❑ Script deployment flows instead of repetitive clicks

❑ Move faster through keyboard than mouse

❑ Combine tools like gsutil, kubectl for workflows

❑ Infrastructure-as-Code principles with Gitops

❑ Installable on any platform with Python

❑ Flexible authentication including Service Accounts

❑ Available completely offline as well!

Let‘s look at some examples:

Creating a Linux VM

GUI Way:

  • Go to Compute Engine » VM Instances
  • Click Create Instance
  • Select options like machine type, disk size etc.
  • Click Create after 5+ clicks

gcloud way:

gcloud compute instances create my-vm --zone=us-central1-a --machine-type=e2-medium --image-family=ubuntu-2004-lts --image-project=ubuntu-os-cloud

Copying files to cloud storage

GUI Method:

  • Go to Cloud Storage browser
  • Select bucket » Upload files (4-5 clicks)

gcloud way:

gsutil cp /my/files gs://my-bucket  

As you can see, CLI commands abstract complexity into easy scripts that can be automated!

Reviewing the State of Cloud and CLI Trends

While adoption rates vary year-on-year, cloud platforms now account for 21% of total IT expenditure, according to Flexera 2022 State of The Cloud Report. Their surveys found that on average, enterprises utilize about 2 different public cloud providers, though GCP, AWS and Azure lead in popularity.

So which access tools are popular among developers? Hummer.io developer surveys found that:

  • 72.2% used cloud CLIs extensively
  • 15.7% used Web UIs predominantly
  • 12.1% were CLI tools skeptics!

Among providers, Google Cloud SDK installation stood at 60.8%, behind AWS CLI but ahead of Azure CLIs.

While UI usage still retains appeal for simplicity, CLI proficiency is essential for DevOps. So whether you need periodic automation or full Infrastructure-as-Code, understanding gcloud installation offers the adaptability to incorporate it in your cloud toolchain!

On that note, let‘s shift gears and jump right into installing the Google Cloud SDK on your desktop OS…

Getting gcloud and Google Cloud SDK on Windows

Google offers a quick Windows Installer to set up the gcloud CLI and supporting tools. With modern functionality and just a few clicks, you can access the power of GCP through WSL or command prompt.

Prerequisites

❑ Windows 7/8/10/11 x64 bit OS
❑ Administrator access to run installer

Installation Steps

1. Download

Get the latest GoogleCloudSDKInstaller from:

https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe

(direct download link)

Save to a convenient location on your system.

2. Run Installer

Double-click the .exe file and authorize admin access when prompted. This launches the set up wizard.

Accept license agreement and use default options:

❑ Install location: C:\Program Files\Google\Cloud SDK
❑ Add to PATH for all users

The wizard also downloads any required Python dependencies critical for gcloud functionality. Wait for completion.

3. Initialize Through Command Prompt

To wrap up SDK configuration, initialize it from the terminal:

gcloud init

The prompts help authorize Access (choose user account or continue browserless) and select a Default Project, Regional settings.

Once finished, gcloud environment is ready! Verify by running:

gcloud --version

And that‘s it! Core gcloud with gsutil, bq installed. You can now utilize CLI administration for GCP via Windows Command Prompt or WSL…

Let‘s continue our set up journey to macOS environment next.

Smooth gcloud Installation on macOS

Google Cloud SDK brings gcloud capabilities for automating infrastructure and application deployments to developer-favorite macOS systems. Installation leverages familiar UNIX-style packages.

While most modern macs already ship with compatible Python versions, the gcloud packaged binaries have specific OS requirements:

Prerequisites

❑ macOS High Sierra 10.13 or higher
❑ Intel x86 / Apple Silicon ARM processors
❑ Administrator access to install packages

Installation Steps

1. Identify Architecture

Determine if your Mac runs Intel/ARM hardware with:

uname -m

2. Download Package

Download the matching gcloud SDK tar.gz archive:

Platform Download URL
Intel x86_64 https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-346.0.0-darwin-x86_64.tar.gz
Apple Silicon ARM 64-bit (M1 / M2 chips) https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-346.0.0-darwin-arm.tar.gz

3. Extract Downloaded Bundle

Double click the .tar.gz package to unpack. Finder will expand the cloud SDK contents including handy install scripts.

In your chosen destination folder, run:

./google-cloud-sdk/install.sh  

Authorize admin rights when prompted during script execution.

4. Initialize gcloud Client Login

Finish setup with:

gcloud init

The initialization will guide you through logging in to your Google account and configuring settings.

After credentials verification and default project selection, gcloud environment is configured for use!

Feel free to test out:

gcloud --version

And you have the powerful CLI ready on macOS as well!

Now let us get it going on Linux…

Installing Google Cloud SDK on Linux Distros

Since Linux is the most popular OS for hosting server applications in the cloud and on-prem, multiple secure package distributions are available for gcloud on:

❑ RHEL, CentOS, Fedora and derivatives

❑ Debian-based like Ubuntu, Linux Mint etc.

❑ Other environments like SUSE Linux, Arch

We will cover the two most common methods.

Prerequisites

❑ Standard version of modern distribution
❑ root or sudo access for installation
❑ curl/wget, unzip, git already available

RHEL/CentOS/Fedora Install

These yum-based distros include straightforward Cloud SDK setup via RPM packages from Google repositories.

Follow the steps below from your terminal:

1. Import Google‘s yum repository key:

sudo curl https://packages.cloud.google.com/yum/doc/yum-key.gpg | sudo rpm --import -

2. Add the SDK repository details:

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=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
       https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOM

3. Install the google-cloud-sdk package:

sudo dnf install google-cloud-sdk

This installs:

❑ gcloud – CLI tool
❑ gsutil – Cloud storage utility
❑ bq – BigQuery interface

Initialize with:

gcloud init

And you‘re all set!

RHEL, Centos and other derivatives can utilize gcloud functionality effectively now.

Ubuntu/Debian/Linux Mint Install

For apt-get managed Debian/Ubuntu distributions, gcloud can be deployed via the following method:

1. Add the signed Cloud SDK distribution URI:

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

This points the repositories from where to fetch.

2. Import Google‘s public key:

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

Verifies authenticity of the downloaded packages.

3. Update list and install:

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

Fetch latest catalog info and get SDK components.

4. Initialize Client

Post-install:

gcloud init  

And gcloud is ready for your Google Cloud!

Installing Additional Components

While gcloud SDK bundles the most common tools like core commands, gsutil, bq, you can enable additional capabilities easily:

Kubectl CLI – installs google-cloud-sdk-kubectl for managing GKE clusters.

App Engine Extensions – deploy applications through gcloud using add-on packages.

Emulator Tools – local env testing against datastore, pubsub, bigtable mock instances.

Based on the Linux distribution‘s package format, search and install each component with its matching name:

APT:

sudo apt install google-cloud-sdk-app-engine-python 

YUM/DNF:

sudo dnf install google-cloud-sdk-datastore-emulator

This way build up CLI functionality for your specific GCP use case!

Next Steps with gcloud

In this detailed guide, we discussed the merits of CLI-driven cloud provisioning and covered multiple methods to get gcloud set up securely across popular OS platforms.

Here are a few next steps to continue your learning:

1. Explore Main Commands

Now that SDK is initialized, try core gcloud services, gsutil cloud storage utility, bigquery data commands

2. Deploy GCP Resources

Provision a VM, Kubernetes cluster; upload/download files to Cloud Storage buckets

3. Automate Scripts

Combine commands with loops, variables for faster infrastructure setup

4. Manage Access

Understand identity and access management (IAM) through service accounts

Google‘s Cloud SDK Documentation and gcloud Cheat Sheet provide expansive references for adoption!

So go ahead, access the versatility of Infrastructure-as-Code in style using CLI on your favorite OS! Your cloud automation journey with GCP has just taken off…

Hope you found this guide helpful. Happy clouding with gcloud 🙂