MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Google Cloud Tutorial – gcloud CLI Install and initialize

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, curl and tar, and a Google account that can access at least one Google Cloud project.
  • Python: gcloud runs 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 the CLOUDSDK_PYTHON environment variable.
  • No install needed in Cloud Shell: Google Cloud Shell in the console comes with gcloud already 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

  1. Choose to sign in. A browser opens for Google login. On a machine with no browser (SSH, a VM), run gcloud init --no-launch-browser and paste the URL into a browser on another machine.
  2. Pick a cloud project from the list, or create a new one.
  3. If the Compute Engine API is enabled, choose a default region and zone. This saves you from passing --region and --zone on every command.
  4. 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

TaskCommand
Update an archive installgcloud components update
Add kubectl and the GKE auth plugingcloud components install kubectl gke-gcloud-auth-plugin
Credentials for Terraform and client librariesgcloud auth application-default login
Separate dev and prod settingsgcloud config configurations create prod then gcloud config configurations activate prod
Authenticate a CI job with a key filegcloud 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

ErrorCauseFix
tar: ...linux-x86.tar.gz: Cannot open: No such fileThe file name passed to tar doesn't match the downloaded fileRun ls *.tar.gz and extract the exact file name
gcloud: command not foundThe shell hasn't reloaded PATH, or you said No to the PATH promptOpen 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 installationgcloud was installed with apt, dnf or another package managerUpdate with the package manager, for example sudo apt-get install --only-upgrade google-cloud-cli
The required property [project] is not currently setNo default project is set in the active configurationgcloud config set project PROJECT_ID or pass --project
Python version errors at startupThe system Python isn't supported and no bundled Python was foundInstall 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 run gcloud auth revoke on machines you no longer use.
  • To uninstall an archive install, delete the google-cloud-sdk directory and ~/.config/gcloud, then remove the lines install.sh added 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

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals

Related Posts

Terraform Tutorial with Google Cloud – Create Single VM & Network

This tutorial uses Terraform to create a Google Compute Engine VM on Google Cloud, either in a new auto-mode VPC network or in the project's default network….

Read More

Terraform Tutorial with Google Cloud – Create Single VM

This tutorial shows how to create a single Google Compute Engine VM with Terraform, using the google_compute_instance resource above as the starting point. The snippet above only…

Read More

Google Cloud Platform Assignment & Excercise

This page is a Google Cloud Platform (GCP) assignment: hands-on exercises for creating a project, assigning IAM roles and launching a labelled Compute Engine VM, followed by…

Read More

GCP vs. On-Prem for DevOps Infrastructure: A Cost and Operational Maturity Comparison

Most engineering teams donโ€™t decide to keep DevOps tooling on-premises. They inherit the decision. A CI runner gets stood up on a spare server, an artifact store…

Read More

Google Cloud Professional DevOps Engineer: Skills and Career Guide

The world of software engineering has changed. A few years ago, knowing how to write code was enough. Today, the industry demands that you also know how…

Read More

Google Cloud: API Gateway Basic Tutorials

Below is a practical, step-by-step Google Cloud API Gateway setup using a dummy backend on Cloud Run (hello service), then testing via curl. This follows Googleโ€™s official…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x