gcloud CLI Explained: Commands, Auth, Config, and Examples
gcloud is the command-line tool for Google Cloud. You install it once and use it to create resources, manage projects, authenticate, deploy services, and automate cloud tasks from your terminal. For anything you do more than once, it is faster than clicking through the Cloud Console. It is also essential for scripting, CI/CD, and multi-project work. This page explains what gcloud is, how it works, and what every beginner needs to know to use it with confidence.
What gcloud CLI is
gcloud is the primary command-line interface for Google Cloud Platform. It is part of the Google Cloud SDK, which bundles gcloud with tools like gsutil (for Cloud Storage) and bq (for BigQuery). When most people say “install the Google Cloud SDK,” they mean getting gcloud.
gcloud runs on Linux, macOS, and Windows. Once installed and authenticated, it gives you full control over GCP resources from your terminal. You use it to create VMs, configure IAM, deploy Cloud Run services, manage Kubernetes clusters, enable APIs, inspect logs, and run any operation that the Cloud Console does through a browser.
Think of GCP as a large building. The Cloud Console is the reception desk: you walk up, look at a board showing every room and its status, and interact through a graphical interface. gcloud is a direct phone line to each room: you say exactly what you need, get a response immediately, and can write down the call script so anyone can repeat it. The reception desk is great when you are new and exploring. The phone is faster once you know what you want.
If you have not installed gcloud yet, the
installation guide
covers macOS, Linux, and Windows setup and walks through the first-time
gcloud init wizard that configures everything interactively.
What you can do with gcloud
gcloud covers every major GCP operation. Here are the categories you will reach for most:
Create and manage resources. Launch VMs, create Cloud Storage buckets, deploy Cloud Run services, manage GKE clusters, set up databases, all from your terminal.
Authenticate and manage accounts. Log in, switch between accounts, set up Application Default Credentials for local development, and activate service accounts.
Configure projects and defaults. Set the active project, default region, and default zone so you do not have to add flags to every command.
Manage IAM and service accounts. Grant and revoke roles, list bindings, and create or manage service accounts without opening a browser.
Enable and inspect APIs. Turn on a Cloud API from the command line, list enabled APIs, and check whether a specific API is active in the current project.
Inspect and debug resources. Describe running VMs, read recent logs, check operation status, and audit what is running in a project without navigating through the Console.
Automate and script cloud tasks. Chain gcloud commands into shell scripts for repeatable setup, CI/CD pipelines, runbooks, and teardown procedures.
How gcloud commands are structured
Every gcloud command follows the same four-part pattern:
gcloud [GROUP] [SUBGROUP] [COMMAND] [FLAGS]- GROUP: the GCP service or area:
compute,storage,iam,run,container - SUBGROUP: the resource type within that service:
instances,buckets,service-accounts,clusters - COMMAND: the action to perform:
create,list,describe,delete,update - FLAGS: options that modify the command:
—zone=us-central1-a,—format=json,—quiet
The pattern is consistent across all services. Once you know it, you can guess new commands correctly before looking them up:
# List all VM instances in the current project
gcloud compute instances list
# Create a VM instance
gcloud compute instances create my-vm \
--zone=us-central1-a \
--machine-type=e2-micro
# Describe a specific instance in full detail
gcloud compute instances describe my-vm --zone=us-central1-a
# Delete a VM instance
gcloud compute instances delete my-vm --zone=us-central1-aThe same verb pattern applies across every group. gcloud run services list,
gcloud storage buckets list, gcloud iam service-accounts list
all follow the same shape. Learn it once and it works everywhere.
Most gcloud commands require the relevant GCP API to be enabled in your project first.
If you get an error saying the API is not enabled,
enabling it is a one-command fix:
gcloud services enable compute.googleapis.com. The error message usually
tells you the exact API name to use.
First gcloud commands to learn
If you are new to gcloud, start with these. They are safe, read-only or low-risk, and immediately useful for orienting yourself in a project.
# Log in with your Google account
gcloud auth login
# See all current settings (project, region, zone, account)
gcloud config list
# Set the active project
gcloud config set project PROJECT_ID
# List all projects your account has access to
gcloud projects list
# List all VM instances in the current project
gcloud compute instances list
# List all Cloud Run services in a region
gcloud run services list --region=us-central1
# List all APIs enabled in the current project
gcloud services list --enabled
# Get help for any command
gcloud compute instances create --helpThe —help flag works on every command and subgroup. When you are not
sure of the exact flags or syntax, run gcloud [command] —help before
searching online. The built-in documentation includes examples and is always accurate.
How authentication works in gcloud
gcloud needs to know who you are before it can call any GCP API. There are two separate credential types, each serving a different purpose. Mixing them up is one of the most common beginner mistakes, and the errors it produces look like permission problems rather than authentication problems.
# Authenticate the gcloud CLI with your Google account
# (opens a browser window for interactive login)
gcloud auth login
# Set up Application Default Credentials for GCP client libraries
# (required separately when writing code that calls GCP APIs locally)
gcloud auth application-default login
# Authenticate as a service account using a key file
gcloud auth activate-service-account --key-file=key.json
# See which accounts are authenticated and which is currently active
gcloud auth listgcloud auth login authenticates your gcloud CLI. It is what lets
you run gcloud commands in the terminal. It does nothing for application code.
gcloud auth application-default login sets up Application Default
Credentials (ADC): the credential that GCP client libraries (Python, Java, Go,
Node.js) use when your application code calls GCP APIs. When developing locally,
you need to run both commands. Running only one of them is why “it works in the
terminal but fails in my code” is such a common problem.
When each credential type applies
gcloud auth login is for running gcloud commands interactively in your terminal. Use this when setting up gcloud for the first time or when switching accounts.
gcloud auth application-default login is for local development where your code uses GCP client libraries. The libraries pick up ADC credentials automatically, so this command makes your personal Google account available to them without hardcoding anything.
Service account key activation is for running gcloud in automated environments (scripts, CI/CD) where interactive browser login is not possible. See the service accounts guide for when to use a service account versus your personal identity.
Attached service account (on GCP infrastructure) applies when your code runs on Cloud Run, GKE, or Compute Engine. The attached service account provides ADC automatically via the metadata server. No key files or login commands required.
Understanding the difference between your personal identity and service accounts is important for getting authentication right in real projects.
How configuration works in gcloud
gcloud stores a configuration with your active project, region, and zone. Setting
these defaults saves you from typing —project, —region,
and —zone on every command.
# See all current configuration settings
gcloud config list
# Set the active project
gcloud config set project my-project-id
# Set a default region and zone
gcloud config set compute/region us-central1
gcloud config set compute/zone us-central1-a
# Check what a single setting is currently set to
gcloud config get-value project
gcloud config get-value compute/region
# Unset a value and return to requiring the flag explicitly
gcloud config unset compute/zoneThe active project matters most. Commands that create, list, or modify resources
operate on the project in your configuration unless you override it with
—project=PROJECT_ID for a single command. Setting the wrong project
and running a destructive command is one of the more painful beginner mistakes.
Run gcloud config get-value project to confirm the active project
before any delete, update, or set-iam-policy
command. It takes two seconds and prevents a lot of pain.
Setting a default region and zone is also worth doing early. Without them, region-specific commands either prompt interactively or fail with an error. Most teams pick the region closest to their users and set it once per project configuration.
Named configurations for multi-project work
If you work across multiple GCP projects, switching settings one by one each time is slow and error-prone. Named configurations let you save a full set of settings under a name and switch all of them in one command.
A named configuration is like a browser profile: one for personal use, one for work. Each profile remembers its own accounts, bookmarks, and settings. Switch profiles and everything updates at once. With gcloud, one configuration per environment means switching from dev to prod is a single command, not four config-set commands you might forget to run completely.
Each named configuration stores a project, region, zone, and account. A developer working across dev, staging, and production would create three separate configurations:
# Create a named configuration for production
gcloud config configurations create prod
gcloud config set project acme-api-prod
gcloud config set compute/region europe-west1
gcloud config set account alice@acme.com
# Create another configuration for development
gcloud config configurations create dev
gcloud config set project acme-api-dev
gcloud config set compute/region us-central1
gcloud config set account alice@acme.com
# Switch to the production configuration
gcloud config configurations activate prod
# Switch back to development
gcloud config configurations activate dev
# List all configurations and see which is active
gcloud config configurations listAdd the active gcloud configuration to your shell prompt so you always see which context you are in. This prevents running a command in the wrong environment. Most terminal customisation tools (Starship, Oh My Zsh, Powerlevel10k) support a gcloud context segment.
gcloud vs Cloud Console: when to use each
gcloud and the Cloud Console call the same underlying GCP APIs. They are not competitors. Most cloud engineers use both daily. The question is which one is faster for the task in front of you.
| gcloud CLI | Cloud Console | |
|---|---|---|
| Best for | Scripting, automation, repeatable work | Exploration, visual debugging, first-time setup |
| Access | Terminal; install locally or use Cloud Shell | Any browser, nothing to install |
| Reproducibility | Commands can be copied, versioned, scripted | Clicks cannot be version-controlled |
| Discovery | You need to know what you are looking for | Browse services visually, see all options at once |
| Debugging | —verbosity=debug for HTTP-level detail | IAM Policy Troubleshooter and Logs Explorer are faster visually |
| Learning | —help and reference docs | UI forms surface all options with labels and hints |
A practical rule: reach for the Console when you are exploring, checking live status, or debugging visually. Reach for gcloud when you are building, automating, or doing something you will repeat. Over time, most engineers move more daily work into gcloud commands because commands are reproducible and can live in version control.
The Console shows a gcloud equivalent command at the bottom of most resource creation forms. Configure something through the UI, copy the generated gcloud command, and save it. This is one of the fastest ways to learn the correct flags for services you already know how to configure visually.
When gcloud is the right tool
Certain workflows become significantly easier once you reach for gcloud instead of the browser:
Repeatable setup. Creating the same set of resources across dev, staging, and production is tedious in the Console and error-prone when done by hand. A gcloud script runs identically every time.
CI/CD pipelines. Deployment pipelines (GitHub Actions, Cloud Build, Jenkins) use gcloud commands to deploy Cloud Run services, update GKE configurations, or push container images. No browser involved.
Automation and scripting. Scheduled cleanup scripts, resource inventory checks, and automated environment teardown all benefit from gcloud’s consistent output formats and scriptable behaviour.
Multi-project work. Switching between projects with named configurations is faster than navigating the project picker in the Console and waiting for the page to reload.
Faster troubleshooting. Listing all running VMs, checking which APIs are enabled, or reading recent log entries is often one command away in the terminal, which is faster than navigating several pages in the Console.
Documentation and runbooks. A gcloud command in a runbook can be copied and executed directly. A Console instruction like “click the button next to the resource name” ages poorly and breaks when the UI changes.
Working without a browser. SSH sessions, remote servers, and Cloud Shell all work fine with gcloud. The Console is not always available.
Output formats
By default, gcloud returns human-readable tables. These work well for quick reading
but are not useful in scripts. Use —format to control what you get:
# Default table output (human-readable)
gcloud compute instances list
# JSON output (pipe to jq, use in scripts, parse in code)
gcloud compute instances list --format=json
# YAML output (readable and structured)
gcloud compute instances list --format=yaml
# Custom table showing only the columns you care about
gcloud compute instances list \
--format="table(name,zone,status,machineType)"
# Extract a single value for use in a shell variable
gcloud compute instances describe my-vm \
--zone=us-central1-a \
--format="value(networkInterfaces[0].accessConfigs[0].natIP)"The value() format is particularly useful in scripts. It extracts a
single field as plain text with no table headers or decorations, so you can assign
it directly to a shell variable:
IP=$(gcloud compute instances describe my-vm \
--zone=us-central1-a \
--format="value(networkInterfaces[0].accessConfigs[0].natIP)")
echo "Connecting to: $IP"
ssh user@"$IP"Global flags worth knowing
These flags work on every gcloud command and are worth learning early:
—project=PROJECT_ID: override the active project for one command without changing your configuration. Useful when you need to check something in another project quickly.—quiet/-q: suppress confirmation prompts. Essential in scripts where interactive input is not possible.—verbosity=debug: print the underlying HTTP requests gcloud makes. Invaluable when a command fails with an unclear error. Shows the exact API call and the full response body.—async: return immediately after submitting a long-running operation instead of waiting for it to complete. The operation continues in the background.—format=FORMAT: control the output format for any command. See the output formats section above.—help/-h: show documentation, flags, and examples for any command or subgroup. Run this before searching online.
—quiet suppresses the “are you sure?” confirmation on destructive
commands like delete. It is the right flag for scripts. It is a
risky habit in interactive sessions. Do not reach for -q just to
save a keystroke when running commands manually, especially against production
resources.
# Delete a VM without the confirmation prompt, in a specific project
gcloud compute instances delete my-vm \
--zone=us-central1-a \
--project=my-other-project \
--quiet
# See the HTTP calls gcloud makes under the hood
gcloud compute instances list --verbosity=debug 2>&1 | head -50
# Start a long-running cluster creation and return immediately
gcloud container clusters create my-cluster \
--zone=us-central1-a \
--asyncA basic workflow for getting started
If you have just installed gcloud or are setting it up on a new machine, follow these steps in order. Each one builds on the last.
Install gcloud. Follow the installation guide for your operating system. Run
gcloud versionto confirm it worked.Log in. Run
gcloud auth login. A browser window opens. Sign in with the Google account that has access to your GCP project. gcloud stores the credential locally.Set your project. Run
gcloud config set project PROJECT_IDwith your actual project ID, not the project name. Find the ID in the Cloud Console project picker or by runninggcloud projects list.Set a default region. Run
gcloud config set compute/region REGIONwith the region closest to your users or where your resources will live. See regions and zones if you are not sure which to pick.Confirm your configuration. Run
gcloud config listto verify the project, region, and account all look correct.Run a read-only command first. Try
gcloud projects listorgcloud services list —enabledto confirm authentication and project settings are working before doing anything that creates or modifies resources.Set up Application Default Credentials if you are writing code. Run
gcloud auth application-default loginif you are building an application that calls GCP APIs using client libraries. Make sure the relevant APIs are enabled in your project first.
Common mistakes with gcloud
Operating in the wrong active project. The most costly mistake. Run
gcloud config get-value projectbefore any command that deletes, modifies, or creates resources. Named configurations help: switching contexts becomes one command instead of a sequence of config-set calls.Confusing gcloud auth login with Application Default Credentials.
gcloud auth loginauthenticates the CLI. Your application code that uses GCP client libraries needs a separate credential set up withgcloud auth application-default login. Forgetting the second one produces errors that look like permission problems but are actually authentication problems.Not setting a default project after installation. Without a default project, most resource commands fail or prompt interactively on every invocation. Set it immediately after
gcloud auth loginwithgcloud config set project PROJECT_ID.Not using —help when stuck. The built-in help is comprehensive, accurate, and includes examples. Run
gcloud [command] —helpbefore reaching for a search engine.gcloud compute instances create —helplists every available flag with explanations.Using —quiet on destructive commands in the wrong context.
—quietskips confirmation prompts, which is useful in scripts but dangerous in interactive sessions. Do not add-qto commands you are running manually unless you are certain of the target resource and project.Not realising the Console and gcloud have separate active projects. The project in your gcloud configuration and the project selected in the Console do not sync automatically. They can silently point to different projects at the same time. Always verify both when debugging unexpected behaviour across tools.
Summary
- gcloud is Google Cloud’s command-line tool for creating resources, managing projects, and automating tasks
- Commands follow the pattern:
gcloud [GROUP] [SUBGROUP] [COMMAND] [FLAGS] - Run
gcloud auth loginto authenticate the CLI; rungcloud auth application-default loginseparately for client library credentials - Set a default project, region, and zone with
gcloud config setto avoid adding flags to every command - Use named configurations to switch between full project contexts in one command
- Use
—format=jsonorvalue()for script-friendly output - Run
—helpon any command before searching online - Always confirm the active project before any destructive command
Frequently asked questions
What is the gcloud CLI?
gcloud is the primary command-line interface for Google Cloud. It is part of the Google Cloud SDK and runs on Linux, macOS, and Windows. You use it to create and manage GCP resources, configure IAM, enable APIs, deploy services, and automate workflows with shell scripts. Most actions available in the Cloud Console can also be done with gcloud, and commands can be version-controlled and reused.
Is gcloud the same as the Google Cloud SDK?
Not exactly. The Google Cloud SDK is the package that contains gcloud along with other tools like gsutil (for Cloud Storage) and bq (for BigQuery). When you install the Cloud SDK, you get gcloud as the main tool plus these companions. Most people say "install gcloud" when they mean installing the full SDK.
How do I change the active project in gcloud?
Run gcloud config set project PROJECT_ID to change the active project for all subsequent commands. To override it for a single command without changing your configuration, add --project=PROJECT_ID to that command. For teams working across many projects, named configurations let you switch a full set of settings (project, region, zone, and account) with one command.
What is the difference between gcloud auth login and application-default login?
gcloud auth login authenticates the gcloud CLI itself so you can run gcloud commands in your terminal. gcloud auth application-default login sets up Application Default Credentials (ADC), which GCP client libraries (Python, Java, Go, Node.js) use when your application code calls GCP APIs. When developing locally, you typically need to run both. On GCP infrastructure like Cloud Run or GKE, ADC is provided automatically by the attached service account.
Should I use gcloud or Cloud Shell?
They are not mutually exclusive. Cloud Shell is a browser-based terminal that comes with gcloud pre-installed and pre-authenticated. Use Cloud Shell when you need to run gcloud commands without installing anything locally. Install gcloud locally when you want to work from your own terminal, use it in CI/CD pipelines, or run it inside scripts on your machine.
How do I check which account and project are active in gcloud?
Run gcloud config list to see all current settings including the active project, region, zone, and account. To check a single value, run gcloud config get-value project or gcloud config get-value account. Run gcloud auth list to see all authenticated accounts and which is currently active.