Live
OpenTelemetry tracing expands across Cloudflare’s proxy stack in betaDynamic Model Triage: Engineering Implications of Grok Bot’s Multi‑Model BackendAccess Cloudflare Skills Directly Through the API MCP ServerCodeQL 2.27.2 expands language models and tightens macOS build support – what engineers need to knowTangible Certification: Turning a Kubernetes Badge into a Gold NecklaceGoogle Data Cloud GA updates: agent‑centric tooling, hybrid Spanner, and expanded Lakehouse catalogCloudflare folds Deno runtime into Workers: practical impact on serverless deploymentsManaging Copilot Code Review Costs and License Scope with New Org‑Level ControlsOpenTelemetry tracing expands across Cloudflare’s proxy stack in betaDynamic Model Triage: Engineering Implications of Grok Bot’s Multi‑Model BackendAccess Cloudflare Skills Directly Through the API MCP ServerCodeQL 2.27.2 expands language models and tightens macOS build support – what engineers need to knowTangible Certification: Turning a Kubernetes Badge into a Gold NecklaceGoogle Data Cloud GA updates: agent‑centric tooling, hybrid Spanner, and expanded Lakehouse catalogCloudflare folds Deno runtime into Workers: practical impact on serverless deploymentsManaging Copilot Code Review Costs and License Scope with New Org‑Level Controls
Google Cloud

Google Cloud gcloud CLI: Complete Setup and Command Reference

Overview

This tutorial covers the complete setup and everyday usage of the Google Cloud CLI (gcloud) — the primary command-line interface for interacting with Google Cloud Platform services. You will learn how to install and authenticate gcloud, manage projects and configurations, and run real commands against core GCP services.

Prerequisites:

  • A Google Cloud account (free tier works fine)
  • A terminal: Bash on Linux/macOS or Cloud Shell
  • Basic familiarity with command-line interfaces

Why this matters for the Google Cloud Digital Leader (CDL): The CDL exam tests your understanding of how Google Cloud is accessed and managed. Knowing what the gcloud CLI does, how authentication works, and how projects are structured directly maps to CDL objectives around cloud operations, resource management, and Google Cloud's core tooling.

Getting Started

The fastest way to use gcloud is via Google Cloud Shell, which comes pre-installed in the GCP Console. For local use, install the Google Cloud SDK.

Install on Linux/macOS (recommended method):

# Download and run the install script
curl https://sdk.cloud.google.com | bash

# Restart your shell, then initialize
exec -l $SHELL
gcloud init

Install on macOS via Homebrew:

brew install --cask google-cloud-sdk

Install on Windows (PowerShell):

# Download the installer from https://cloud.google.com/sdk/docs/install
# Then run in PowerShell:
(New-Object Net.WebClient).DownloadFile("https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe", "$env:Temp\GoogleCloudSDKInstaller.exe")
& $env:Temp\GoogleCloudSDKInstaller.exe

After installation, run gcloud init to authenticate and set a default project:

# Interactive setup: login, select project, set default region
gcloud init

# Verify the installed version
gcloud version

# Check active configuration
gcloud config list

Authentication and Project Management

Google Cloud uses Application Default Credentials (ADC) and user accounts to control access. Understanding authentication is critical for both daily operations and the CDL exam.

Authenticate as a user:

# Opens browser for OAuth2 login
gcloud auth login

# Authenticate for ADC (used by SDKs and client libraries)
gcloud auth application-default login

# List all authenticated accounts
gcloud auth list

# Set the active account
gcloud config set account your-email@example.com

Manage projects — the foundation of GCP resource organization:

# List all projects your account can access
gcloud projects list

# Set a default project for all commands
gcloud config set project my-project-id

# Get details about a specific project
gcloud projects describe my-project-id

# Create a new project
gcloud projects create my-new-project --name="My New Project"

# Enable a specific API on a project
gcloud services enable compute.googleapis.com --project=my-project-id

Common pitfall: Many gcloud commands will fail with a "project not set" error if you skip setting a default project. Always confirm your active project with gcloud config get-value project before running resource commands.

Named configurations let you switch between projects and accounts quickly:

# Create a named config for a staging environment
gcloud config configurations create staging
gcloud config set project my-staging-project
gcloud config set account devops@example.com
gcloud config set compute/region us-central1

# List all configurations
gcloud config configurations list

# Switch to a different configuration
gcloud config configurations activate staging

Working with Core GCP Services

Once authenticated, you can manage compute, storage, and networking resources entirely from the CLI. These examples reflect real-world workflows used in production environments.

Compute Engine (Virtual Machines):

# List all VM instances in your project
gcloud compute instances list

# Create a lightweight VM for testing
gcloud compute instances create my-vm \
  --machine-type=e2-micro \
  --zone=us-central1-a \
  --image-family=debian-12 \
  --image-project=debian-cloud

# SSH into an instance (gcloud handles key management automatically)
gcloud compute ssh my-vm --zone=us-central1-a

# Stop and delete an instance
gcloud compute instances stop my-vm --zone=us-central1-a
gcloud compute instances delete my-vm --zone=us-central1-a

Cloud Storage (GCS):

# Create a new storage bucket (bucket names must be globally unique)
gcloud storage buckets create gs://my-unique-bucket-2024 --location=us-central1

# Upload a file to a bucket
gcloud storage cp ./report.pdf gs://my-unique-bucket-2024/reports/

# List objects in a bucket
gcloud storage ls gs://my-unique-bucket-2024/

# Download a file
gcloud storage cp gs://my-unique-bucket-2024/reports/report.pdf ./local-copy.pdf

# Delete a bucket and all its contents
gcloud storage rm -r gs://my-unique-bucket-2024

IAM — managing who can do what:

# View IAM policy for a project
gcloud projects get-iam-policy my-project-id

# Grant a role to a user
gcloud projects add-iam-policy-binding my-project-id \
  --member="user:engineer@example.com" \
  --role="roles/storage.objectViewer"

# Grant a role to a service account
gcloud projects add-iam-policy-binding my-project-id \
  --member="serviceAccount:my-sa@my-project-id.iam.gserviceaccount.com" \
  --role="roles/compute.viewer"

# List available roles
gcloud iam roles list --filter="stage=GA"

Best practice: Use service accounts for application-to-GCP authentication rather than user credentials. Apply the principle of least privilege — grant only the permissions required for the task.

Useful global flags for every command:

# Output as JSON for scripting
gcloud compute instances list --format=json

# Output as a filtered table
gcloud compute instances list --format="table(name,zone,status,machineType)"

# Filter results
gcloud compute instances list --filter="status=RUNNING"

# Run without confirmation prompts (useful in CI/CD)
gcloud compute instances delete my-vm --zone=us-central1-a --quiet

Exam Tips for Google Cloud Digital Leader (CDL)

The CDL exam is conceptual but expects you to understand what tools do and when to use them. Here are high-yield topics:

Key concepts tested on the exam:

  • gcloud vs Console vs APIs: All three access the same GCP services. gcloud is best for automation and scripting; the Console is best for visualization and one-off tasks.
  • Projects as billing and resource boundaries: Every GCP resource belongs to exactly one project. Projects are the primary unit of organization, billing, and access control.
  • IAM hierarchy: Policies can be set at Organization, Folder, Project, or Resource level. Permissions are inherited downward.
  • Service accounts: Machine identities used by applications — not humans. Key exam scenario: a Cloud Function needs to read from Cloud Storage → attach a service account with roles/storage.objectViewer.
  • Cloud Shell: A free, browser-based shell with gcloud pre-installed. Useful for quick tasks without local SDK setup.

Common exam scenarios:

  1. A developer needs to deploy code from CI/CD — use a service account with scoped roles, not a personal account.
  2. You need to give a team read-only access to all VMs — grant roles/compute.viewer at the project level.
  3. You want to automate resource creation nightly — use gcloud commands in a Cloud Scheduler + Cloud Run pipeline.

Quick reference commands for exam review:

# Check active project and account
gcloud config list

# List enabled APIs
gcloud services list --enabled

# Describe a resource (works for most resource types)
gcloud compute instances describe my-vm --zone=us-central1-a

# Get help for any command
gcloud compute instances create --help

Summary

Key takeaways from this tutorial:

  • The gcloud CLI is the primary tool for managing GCP resources programmatically and is essential for any cloud engineer working on Google Cloud.
  • Authentication flows through gcloud auth login for users and service accounts for applications — always prefer service accounts in automated pipelines.
  • Projects are the core organizational unit in GCP. Set your default project early and use named configurations to manage multiple environments cleanly.
  • The --format and --filter flags transform gcloud from a manual tool into a powerful scripting utility.
  • For the CDL exam, focus on understanding what gcloud does conceptually: it talks to the same GCP APIs as the Console, making it interchangeable but better suited for automation and repeatability.

Next steps:

  • Practice with Google Cloud Shell — no local install required
  • Explore the official gcloud reference documentation
  • Work through the Google Cloud Digital Leader learning path on Google Cloud Skills Boost
  • Read our related guide: Google Cloud IAM: Roles, Policies, and Service Accounts Explained on CloudNinjas.ca