This page shows how to install the Google Cloud CLI (gcloud) on Linux from the official archive, then run gcloud init to sign in and pick a default project, region and zone. Below the original steps you will find a corrected script, package-manager installs for Debian/Ubuntu, RHEL and macOS, a way to check the setup, and fixes for the errors people hit most often.
What the steps above do
The Google Cloud CLI is a set of command-line tools for creating and managing Google Cloud resources. It includes gcloud, gsutil and bq. The steps above download a tarball, extract it to a google-cloud-sdk directory, run install.sh to add the tools to your PATH and turn on shell completion, and then run gcloud init to authenticate and save default settings.
- Prerequisites: a 64-bit Linux machine,
curlandtar, and a Google account that can access at least one Google Cloud project. - Python:
gcloudruns on Python 3. Recent Linux archives ship with a bundled Python. If your system has an unsupported Python version, point the CLI at a supported one with theCLOUDSDK_PYTHONenvironment variable. - No install needed in Cloud Shell: Google Cloud Shell in the console comes with
gcloudalready installed and authenticated.
Corrected Linux install script
The gist above can't run as written. It downloads the x86_64 archive and then tries to extract a file named ...-linux-x86.tar.gz, so tar stops with a 'No such file' error. Several lines of instructions are also not commented out, so the file fails if you run it as a shell script. It also pins version 386.0.0, which is now very old. Google publishes an unversioned download that always points to the current release. Use that instead.
#!/usr/bin/env bash
set -euo pipefail
cd "$HOME"
# Pick the archive for your CPU (check with: uname -m)
# x86_64 -> google-cloud-cli-linux-x86_64.tar.gz
# aarch64 -> google-cloud-cli-linux-arm.tar.gz
ARCHIVE=google-cloud-cli-linux-x86_64.tar.gz
curl -O "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${ARCHIVE}"
# To replace an existing install, remove the old directory first
# rm -rf "$HOME/google-cloud-sdk"
tar -xf "${ARCHIVE}"
# Interactive install: answers prompts for usage stats, PATH and completion
./google-cloud-sdk/install.sh
# Load the PATH change into the current shell (or open a new terminal)
source "$HOME/.bashrc"
gcloud initCode language: PHP (php)
For automated builds, golden images or Dockerfiles, skip the prompts and give the answers as flags:
./google-cloud-sdk/install.sh --quiet \
--usage-reporting=false \
--path-update=true \
--command-completion=true \
--rc-path="$HOME/.bashrc"Code language: JavaScript (javascript)
Note: If you use zsh, install.sh updates ~/.zshrc. Run source ~/.zshrc instead of ~/.bashrc.
Install with a package manager instead
On servers, package-manager installs are usually easier to maintain because gcloud updates along with the rest of the system. The commands below follow Google's documented repository setup.
# Debian / Ubuntu
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates gnupg curl
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | \
sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | \
sudo tee /etc/apt/sources.list.d/google-cloud-sdk.list
sudo apt-get update && sudo apt-get install -y google-cloud-cliCode language: PHP (php)
# RHEL / Rocky / AlmaLinux 9 (x86_64)
sudo tee /etc/yum.repos.d/google-cloud-sdk.repo << 'EOM'
[google-cloud-cli]
name=Google Cloud CLI
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el9-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOM
sudo dnf install -y google-cloud-cli
# macOS (Homebrew)
brew install --cask google-cloud-sdkCode language: PHP (php)
On Windows, download and run the Google Cloud CLI installer from the official install page. It adds gcloud to PATH and can start gcloud init when it finishes.
What gcloud init asks and how to answer
- Choose to sign in. A browser opens for Google login. On a machine with no browser (SSH, a VM), run
gcloud init --no-launch-browserand paste the URL into a browser on another machine. - Pick a cloud project from the list, or create a new one.
- If the Compute Engine API is enabled, choose a default region and zone. This saves you from passing
--regionand--zoneon every command. - The answers are saved in a named configuration called
default, under~/.config/gcloud.
You can change any of these defaults later without running gcloud init again:
gcloud config set project my-project-id
gcloud config set compute/region us-central1
gcloud config set compute/zone us-central1-aCode language: JavaScript (javascript)
Verify the installation
gcloud version # CLI and component versions
gcloud auth list # active account is marked with *
gcloud config list # account, project, region, zone
gcloud projects list # confirms the credentials actually workCode language: PHP (php)
gcloud config list should print something like the output below. If gcloud projects list returns your projects, authentication and network access are both working.
[compute]
region = us-central1
zone = us-central1-a
[core]
account = you@example.com
project = my-project-id
Your active configuration is: [default]Code language: JavaScript (javascript)
Useful next steps after init
| Task | Command |
|---|---|
| Update an archive install | gcloud components update |
| Add kubectl and the GKE auth plugin | gcloud components install kubectl gke-gcloud-auth-plugin |
| Credentials for Terraform and client libraries | gcloud auth application-default login |
| Separate dev and prod settings | gcloud config configurations create prod then gcloud config configurations activate prod |
| Authenticate a CI job with a key file | gcloud auth activate-service-account --key-file=key.json |
Note: gcloud auth login and gcloud auth application-default login save different credentials. Tools such as Terraform and the client libraries read Application Default Credentials, not the credentials gcloud itself uses. Run both if you use both.
Once the CLI is working, you can deploy services with it. See Google Cloud Run Complete Tutorials or browse more Google Cloud tutorials.
Common errors and fixes
| Error | Cause | Fix |
|---|---|---|
tar: ...linux-x86.tar.gz: Cannot open: No such file | The file name passed to tar doesn't match the downloaded file | Run ls *.tar.gz and extract the exact file name |
gcloud: command not found | The shell hasn't reloaded PATH, or you said No to the PATH prompt | Open a new terminal or source ~/.bashrc. You can also re-run install.sh or call ~/google-cloud-sdk/bin/gcloud directly |
The component manager is disabled for this installation | gcloud was installed with apt, dnf or another package manager | Update with the package manager, for example sudo apt-get install --only-upgrade google-cloud-cli |
The required property [project] is not currently set | No default project is set in the active configuration | gcloud config set project PROJECT_ID or pass --project |
| Python version errors at startup | The system Python isn't supported and no bundled Python was found | Install a supported Python 3 and export CLOUDSDK_PYTHON=/usr/bin/python3.x |
Security and housekeeping
- Don't log in with a personal account on shared servers or CI runners. Use a service account with the fewest roles needed. Where possible, use workload identity federation instead of key files.
- Credentials live in
~/.config/gcloud. Protect that directory, and rungcloud auth revokeon machines you no longer use. - To uninstall an archive install, delete the
google-cloud-sdkdirectory and~/.config/gcloud, then remove the linesinstall.shadded to your shell rc file.
Frequently asked questions
Is gcloud CLI the same as Google Cloud SDK?
Yes. Google renamed the Google Cloud SDK to the Google Cloud CLI. The install directory is still called google-cloud-sdk, and the Homebrew cask still uses the old name.
How do I run gcloud init on a server without a browser?
Run gcloud init --no-launch-browser. It prints a URL. Open the URL on any machine with a browser, sign in, and paste the code it gives you back into the terminal.
How do I check which gcloud version is installed?
Run gcloud version. It lists the CLI version and every installed component. To upgrade an archive install, run gcloud components update.
How do I switch between multiple Google Cloud projects or accounts?
Create a named configuration for each environment with gcloud config configurations create NAME, then switch with gcloud config configurations activate NAME. For a single command, you can use --project instead.
Do I need to run gcloud init again after changing my project?
No. gcloud config set project PROJECT_ID changes the default project in the active configuration. Only run gcloud init again if you want to go through the full setup.
Related tutorials
- More Google Cloud tutorials
- Google Cloud: Google Cloud Run Complete Tutorials
- Google Cloud Professional DevOps Engineer: Skills and Career Guide
- What is Google Cloud Storage and use cases of Google Cloud Storage?
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals