You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
The Google Cloud SDK is a set of command-line tools for managing GCP resources and services. At its core is the gcloud CLI, the primary command-line interface for interacting with Google Cloud. Mastering the gcloud CLI is essential for automating tasks, scripting deployments, and managing resources efficiently.
The Cloud SDK is a collection of tools that includes:
| Tool | Purpose |
|---|---|
| gcloud | The primary CLI for managing GCP resources (compute, networking, IAM, etc.) |
| gsutil | Command-line tool for working with Cloud Storage (uploading, downloading, managing buckets) |
| bq | Command-line tool for BigQuery (running queries, managing datasets and tables) |
| kubectl | Kubernetes command-line tool (included as an optional component) |
The Cloud SDK is available for Windows, macOS, and Linux, and comes pre-installed in Cloud Shell.
brew install google-cloud-sdk
# Add the Cloud SDK distribution URI as a package source
echo "deb [signed-by=/usr/share/keyrings/cloud.google.asc] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee /etc/apt/sources.list.d/google-cloud-sdk.list
# Import the Google Cloud public key
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo tee /usr/share/keyrings/cloud.google.asc
# Update and install
sudo apt-get update && sudo apt-get install google-cloud-cli
Download and run the installer from cloud.google.com/sdk/docs/install.
After installation, initialise the SDK to authenticate and configure defaults:
gcloud init
This interactive command will:
# Authenticate with your Google account
gcloud auth login
This opens a browser window for OAuth authentication.
# Set up application default credentials for local development
gcloud auth application-default login
This creates credentials that client libraries (Python, Java, Node.js, Go) use automatically.
# Authenticate using a service account key file
gcloud auth activate-service-account --key-file=key.json
# List all authenticated accounts
gcloud auth list
The gcloud CLI follows a consistent pattern:
gcloud <group> <subgroup> <command> --flags
For example:
# Create a Compute Engine instance
gcloud compute instances create my-vm \
--zone=us-central1-a \
--machine-type=e2-medium \
--image-family=debian-11 \
--image-project=debian-cloud
# List all Compute Engine instances
gcloud compute instances list
# Delete a Compute Engine instance
gcloud compute instances delete my-vm --zone=us-central1-a
| Group | Description |
|---|---|
gcloud compute | Manage Compute Engine (VMs, disks, networks) |
gcloud container | Manage GKE clusters and workloads |
gcloud storage | Manage Cloud Storage buckets and objects |
gcloud sql | Manage Cloud SQL instances |
gcloud functions | Manage Cloud Functions |
gcloud run | Manage Cloud Run services |
gcloud iam | Manage IAM roles and service accounts |
gcloud projects | Manage projects |
gcloud services | Enable and disable APIs |
The gcloud CLI uses configurations to store default settings. You can have multiple configurations and switch between them.
# Set default project
gcloud config set project my-project-id
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.