Home Google CloudHow to Install the gcloud CLI on Linux and Run Your First Commands

How to Install the gcloud CLI on Linux and Run Your First Commands

by Knowledge Base Linux
install gcloud cli on Linux terminal for Google Cloud

Learning how to install gcloud cli on Linux is one of the most useful skills for any sysadmin working with Google Cloud. When you install gcloud cli, you gain a powerful command-line tool to manage virtual machines, storage, databases, and Kubernetes clusters without clicking through the Console. This guide walks you through the installation, first login, and essential commands you will use every day.

The gcloud CLI is part of the Google Cloud SDK. It provides a unified interface to Google Cloud services, supports scripting and automation, and is essential for CI/CD pipelines and repeatable infrastructure work.

What Is gcloud CLI and Why Sysadmins Use It?

Before you install gcloud cli, it helps to understand what it does. The tool lets you create and manage Compute Engine instances, Cloud Storage buckets, Cloud SQL databases, GKE clusters, and much more. Compared to the web Console, the CLI is faster for repetitive tasks, easier to document, and version-controllable through shell scripts.

Most production teams use gcloud alongside tools like Terraform. Even if you prefer infrastructure as code, gcloud is invaluable for debugging, inspecting live resources, and running one-off commands quickly.

install gcloud cli essential first commands on Linux

Prerequisites

  • A Linux machine — Debian, Ubuntu, or a compatible distribution
  • A Google Cloud account with at least one project
  • sudo access and an internet connection
  • Basic terminal familiarity — if you are new to remote servers, read how to SSH into a Linux server

The official reference is the Google Cloud SDK installation documentation. If you have managed AWS before, concepts will feel familiar — compare with our guide on how to launch an EC2 instance on AWS.

How to Install Gcloud CLI on Debian and Ubuntu

Step 1: Install Dependencies and Add the Repository

sudo apt update
sudo apt install -y apt-transport-https ca-certificates gnupg curl

Next, add the Google Cloud package repository to your apt sources and import its signing key following the official SDK instructions. This registers the cloud-sdk repository so apt can find the google-cloud-cli package securely.

Step 2: Install the Package

sudo apt update && sudo apt install -y google-cloud-cli
gcloud --version

If the version prints correctly, you have managed to install gcloud cli successfully via the apt repository, which also means future updates arrive with your normal system updates.

Alternative: Install Gcloud CLI via Tarball

On distributions without apt, or when you need a specific version, download the archive from the official SDK downloads page, extract it to your home directory, and run the installer script included inside the extracted folder. Restart your shell afterwards so the gcloud command is on your PATH. The tarball method gives you full control but you must update it manually.

Initialize and Authenticate

Run gcloud init

gcloud init

This interactive setup logs you in, lets you pick a project, and sets a default region and zone.

Run gcloud auth login

gcloud auth login
gcloud auth list

On a headless server, use the no-browser option and copy the URL to your local browser. For servers and automation, prefer a service account key or Workload Identity instead of a personal login.

Set Default Project, Region, and Zone After You Install Gcloud CLI

gcloud config set project my-project-id
gcloud config set compute/region us-central1
gcloud config set compute/zone us-central1-a
gcloud config list

Setting defaults saves you from typing --project, --region, and --zone on every command and reduces mistakes.

Essential First Commands

Once you install gcloud cli and configure it, try these safe, read-only commands:

gcloud projects list
gcloud compute instances list
gcloud config list
gcloud compute ssh my-instance --zone=us-central1-a

gcloud compute ssh is especially convenient — it handles keys and OS Login for you. Explore command groups to understand the scope:

  • gcloud compute — virtual machines, disks, networks, firewalls
  • gcloud storage and gsutil — Cloud Storage buckets and objects
  • gcloud sql — Cloud SQL databases
  • gcloud container — Google Kubernetes Engine clusters

Use gcloud --help or gcloud compute --help at any time to discover subcommands.

Updating Components and Managing Configurations

Update Components

gcloud components list
gcloud components update
gcloud components install beta

Note: if you installed via apt, update the CLI itself through apt, and use components only for add-ons.

Multiple Configurations

Working with multiple clients or environments? Create named configurations:

gcloud config configurations list
gcloud config configurations create work
gcloud config configurations activate work
gcloud config configurations activate default

Each configuration stores its own account, project, region, and zone, so you can switch contexts cleanly.

Troubleshooting

Command Not Found

If the shell says gcloud: command not found, the SDK bin directory is not on your PATH. Re-run the install script, restart the terminal, or add the SDK bin folder to PATH in your shell profile.

Authentication Errors

Expired or wrong account errors are fixed with gcloud auth login again and gcloud auth list to confirm the active account. Check that the account has IAM permissions on the selected project.

Python Version Issues

gcloud requires Python 3.8 to 3.13 on Linux. If you see Python errors, check python3 --version and point the SDK Python environment variable to a supported interpreter.

Conclusion

You now know how to install gcloud cli on Linux using the official apt repository or the tarball, initialize it, authenticate, set defaults, and run essential first commands. Make gcloud part of your daily workflow — script common tasks, use named configurations for different projects, and keep components updated. The time you invest to properly install gcloud cli will pay back on every Google Cloud task that follows.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.