Skip to content

Setting Up gcloud Command-Line Tool on Ubuntu

Steps
7
Covers
Ubuntu
Versions & support
About Ubuntu →
On this page 7 steps

The gcloud command-line tool is an essential component for managing resources on Google Cloud Platform (GCP). It provides a flexible and powerful way to control various GCP services directly from the command line. This article focuses on the efficient installation and configuration of the gcloud tool specifically on Ubuntu, one of the most popular Linux distributions.

Ubuntu users often require a straightforward and efficient method to interact with Google Cloud services. The gcloud CLI offers this capability, but its installation and configuration must be handled properly to ensure a seamless experience.

Step 1 of 7Prerequisites

Before starting the installation, ensure your Ubuntu system is up to date:

sudo apt-get update 
sudo apt-get upgrade 

Step 2 of 7Adding the Google Cloud SDK Repository

First, you need to add the Google Cloud SDK distribution URI as a package source:

echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list 

Next, import the Google Cloud public key to ensure the integrity of the package:

curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - 

Step 3 of 7Installing the Google Cloud SDK

Now, update the package list and install the Google Cloud SDK:

sudo apt-get update 
sudo apt-get install google-cloud-sdk 

For additional components like gcloud beta commands or kubectl, you can install them using:

sudo apt-get install google-cloud-sdk-gcloud 
sudo apt-get install kubectl 

Step 4 of 7Initializing the gcloud Tool

After installation, run the following command to initialize the tool:

gcloud init 

This command prompts you to log in with your Google account and select or create a new GCP project. It also allows you to set a default compute region and zone.

Step 5 of 7Configuring the gcloud Environment

Customize your gcloud environment by setting default values for your project and compute zone:

gcloud config set project [YOUR_PROJECT_ID] 
gcloud config set compute/zone [YOUR_COMPUTE_ZONE] 

Step 6 of 7Testing the Installation

Test your installation and configuration by running a basic gcloud command, like listing your active account:

gcloud auth list 

Step 7 of 7Keeping the gcloud CLI Updated

To update the gcloud CLI, simply use:

gcloud components update 

Conclusion

Installing and configuring the gcloud command-line tool on Ubuntu is a straightforward process. By following these steps, developers and system administrators can efficiently manage their Google Cloud resources.

Additional Resources:

With gcloud successfully installed on Ubuntu, you are now equipped to harness the full potential of Google Cloud Platform’s vast array of services directly from your terminal.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

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


Back to top