Install Google Cloud CLI on CentOS 9: A Comprehensive Guide

Google Cloud CLI on CentOS 9

Learn how to install Google Cloud CLI on CentOS 9 with this comprehensive guide. Includes step-by-step commands, configuration tips, and troubleshooting advice to help you manage GCP resources efficiently via the command line.

Table of Contents

Introduction

The Google Cloud CLI, commonly known as gcloud, is an essential tool for developers and system administrators working with Google Cloud Platform (GCP). It provides a command-line interface to manage GCP resources, automate workflows, and streamline cloud operations. This guide will walk you through the steps to install the Google Cloud CLI on CentOS 9, ensuring a smooth setup for your cloud management tasks.


Prerequisites

Before diving into the installation process, ensure you have the following:

  • CentOS 9 System: A machine running CentOS 9 with administrative (root) access.
  • Internet Connection: Required to download packages and updates.
  • Package Management Tools: dnf (the default package manager for CentOS 9) should be available.
  • Optional: Google Cloud account to authenticate and use the CLI effectively.

Google Cloud CLI on CentOS 9


Step 1: Add the Google Cloud SDK Repository

To install the Google Cloud CLI on CentOS 9, you first need to add the official Google Cloud SDK repository to your system. This repository contains the necessary packages for the CLI installation.

  1. Open a terminal window.

  2. Run the following command to add the repository:

				
					sudo tee -a /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
				
			

This command appends the repository information to the google-cloud-sdk.repo file, allowing dnf to fetch packages from Google’s repository.


Step 2: Install the Google Cloud CLI

With the repository added, you can now install the Google Cloud CLI using the dnf package manager. Update your package list to ensure you have the latest repository information:

				
					sudo dnf update -y
				
			

Install the Google Cloud CLI package:

				
					sudo dnf install google-cloud-cli
				
			
Google Cloud CLI on CentOS 9

Photo by admingeek from Infotechys

This command installs the core components of the Google Cloud CLI, including gcloud, gsutil, and bq.


Step 3: Initialize the Google Cloud CLI

After installation, it’s essential to initialize the CLI to configure your environment and authenticate your Google Cloud account. Run the initialization command:

				
					gcloud init
				
			

Follow the on-screen prompts to:

  • Authenticate with your Google account.
  • Set a default project.
  • Choose a default compute region and zone.

This setup ensures that your gcloud commands interact with the correct project and resources


Optional: Install Additional Components

Depending on your needs, you might require additional components to extend the functionality of the Google Cloud CLI. These components can be installed as needed. To list available components:

				
					gcloud components list
				
			
				
					
Your current Google Cloud CLI version is: 524.0.0
The latest available version is: 524.0.0

┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                    Components                                                   │
├───────────────┬──────────────────────────────────────────────────────┬──────────────────────────────┬───────────┤
│     Status    │                         Name                         │              ID              │    Size   │
├───────────────┼──────────────────────────────────────────────────────┼──────────────────────────────┼───────────┤
│ Not Installed │ App Engine Go Extensions                             │ app-engine-go                │   4.7 MiB │
│ Not Installed │ Appctl                                               │ appctl                       │  21.0 MiB │
│ Not Installed │ Artifact Registry Go Module Package Helper           │ package-go-module            │   < 1 MiB │
│ Not Installed │ Cloud Bigtable Command Line Tool                     │ cbt                          │  20.0 MiB │
│ Not Installed │ Cloud Bigtable Emulator                              │ bigtable                     │   7.8 MiB │
│ Not Installed │ Cloud Datastore Emulator                             │ cloud-datastore-emulator     │  36.2 MiB │
│ Not Installed │ Cloud Firestore Emulator                             │ cloud-firestore-emulator     │  46.9 MiB │
│ Not Installed │ Cloud Pub/Sub Emulator                               │ pubsub-emulator              │  62.4 MiB │
│ Not Installed │ Cloud Run Proxy                                      │ cloud-run-proxy              │  13.3 MiB │
│ Not Installed │ Cloud SQL Proxy v2                                   │ cloud-sql-proxy              │  15.4 MiB │
│ Not Installed │ Cloud Spanner Emulator                               │ cloud-spanner-emulator       │  37.7 MiB │
│ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr        │   1.8 MiB │
│ Not Installed │ Kustomize                                            │ kustomize                    │   4.3 MiB │
│ Not Installed │ Log Streaming                                        │ log-streaming                │  18.2 MiB │
│ Not Installed │ Managed Flink Client                                 │ managed-flink-client         │ 383.4 MiB │
│ Not Installed │ Minikube                                             │ minikube                     │  45.2 MiB │
│ Not Installed │ Nomos CLI                                            │ nomos                        │  33.3 MiB │
│ Not Installed │ On-Demand Scanning API extraction helper             │ local-extract                │  31.6 MiB │
│ Not Installed │ Skaffold                                             │ skaffold                     │  33.7 MiB │
│ Not Installed │ Spanner migration tool                               │ spanner-migration-tool       │  29.0 MiB │
│ Not Installed │ Terraform Tools                                      │ terraform-tools              │  66.6 MiB │
│ Not Installed │ anthos-auth                                          │ anthos-auth                  │  22.0 MiB │
│ Not Installed │ config-connector                                     │ config-connector             │  91.1 MiB │
│ Not Installed │ enterprise-certificate-proxy                         │ enterprise-certificate-proxy │  10.5 MiB │
│ Not Installed │ gcloud app Java Extensions                           │ app-engine-java              │ 136.7 MiB │
│ Not Installed │ gcloud app Python Extensions                         │ app-engine-python            │   3.8 MiB │
│ Not Installed │ gcloud app Python Extensions (Extra Libraries)       │ app-engine-python-extras     │   < 1 MiB │
│ Not Installed │ gke-gcloud-auth-plugin                               │ gke-gcloud-auth-plugin       │   3.5 MiB │
│ Not Installed │ istioctl                                             │ istioctl                     │  25.7 MiB │
│ Not Installed │ kpt                                                  │ kpt                          │  15.3 MiB │
│ Not Installed │ kubectl                                              │ kubectl                      │   < 1 MiB │
│ Not Installed │ kubectl-oidc                                         │ kubectl-oidc                 │  22.0 MiB │
│ Not Installed │ pkg                                                  │ pkg                          │           │
│ Installed     │ BigQuery Command Line Tool                           │ bq                           │   1.8 MiB │
│ Installed     │ Bundled Python 3.12                                  │ bundled-python3-unix         │  89.3 MiB │
│ Installed     │ Cloud Storage Command Line Tool                      │ gsutil                       │  11.8 MiB │
│ Installed     │ Google Cloud CLI Core Libraries                      │ core                         │  21.7 MiB │
│ Installed     │ Google Cloud CRC32C Hash Tool                        │ gcloud-crc32c                │   1.4 MiB │
│ Installed     │ gcloud Alpha Commands                                │ alpha                        │   < 1 MiB │
│ Installed     │ gcloud Beta Commands                                 │ beta                         │   < 1 MiB │
└───────────────┴──────────────────────────────────────────────────────┴──────────────────────────────┴───────────┘
...omitted for brevity...

				
			

To install a specific component: 

				
					gcloud components install COMPONENT_ID
				
			

Replace COMPONENT_ID with the desired component’s identifier.


Verification

To verify that the Google Cloud CLI is installed and functioning correctly. Check the installed version:

				
					gcloud --version
				
			

List the active configuration:

				
					gcloud config list
				
			
				
					[core]
account = your@gmail.com
disable_usage_reporting = True
project = your_google_cloud_project_id

Your active configuration is: [default]


				
			

These commands should display the current version and configuration settings, confirming a successful installation.


Troubleshooting

IssueSolution
Command not foundEnsure the Google Cloud SDK is installed and the PATH is set correctly.
Authentication errorsRe-run gcloud init to re-authenticate.
Missing componentsInstall missing components using gcloud components install.
Repository errorsCheck the repository URL and ensure your system’s date and time are correct.

Updating the Google Cloud CLI

To keep your Google Cloud CLI up to date. Update the package list:

				
					sudo dnf update
				
			

Upgrade the installed packages:

				
					sudo dnf upgrade google-cloud-cli
				
			

Regular updates ensure you have the latest features and security patches.


Conclusion

Installing the Google Cloud CLI on CentOS 9 is a straightforward process that enhances your ability to manage and automate tasks within Google Cloud Platform. By following the steps outlined in this guide, you can set up a robust command-line environment tailored to your cloud management needs. 

Did you find this article helpful? Your feedback is invaluable to us! Feel free to share this post with those who may benefit, and let us know your thoughts in the comments section below.


Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *