Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

google cloud
ubuntu
debian

How to install Google Cloud CLI on Debian/Ubuntu?

Rauf Tabassam

Pre-requisites

Before the installation of the gcloud CLI, please confirm that the following conditions are met:

  • The OS release has not reached the end-of-life.

  • The apt-transport-http package is installed. If not, use the following command to install it:

    sudo apt-get install apt-transport-https ca-certificates gnupg
    

Package details

The Google Cloud CLI contains the following command-line tools and supported commands:

Command-line Tools Supported Commands
gcloud gcloud, gcloud alpha, gcloud beta
gsutil gsutil
bq bs

However, this package does not contain kubectl or deployment extensions of App Engine but these can be installed.

Installation steps

Perform the following steps to install the Google Cloud CLI:

Step 1: Add gcloud CLI distribution

Use the following command to add the gcloud CLI distribution URI as a packet source:

  • If the OS release supports the signed-by option:
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
  • If the OS release does not support the signed-by option:
echo "deb https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list

Note: Verify that there aren’t any duplicated data for the cloud-sdk repo in /etc/apt/sources.list.d/google-cloud-sdk.list.

Step 2: Acquire the public key

You can acquire the public Key for Google Cloud by executing one of the following commands depending on the type of your distribution:

  • Execute the following command if your distribution’s apt-key command supports the --keyring argument:
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
  • Execute the following command if your distribution’s apt-key command does not support the --keyring argument:
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
  • Execute the following command if your distribution does not support apt-key:
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo tee /usr/share/keyrings/cloud.google.gpg

Step 3: Install gcloud

Run the following command to update and install the gcloud CLI:

sudo apt-get update && sudo apt-get install google-cloud-cli

Step 4: Install additional components (optional)

Additional components of Google Cloud can be installed using the following command:

sudo apt-get install [component_name]

Step 5: Initialize the gcloud CLI

Use the following command to initialize the gcloud CLI:

gcloud init

Installation on Docker

If you want to install the gcloud CLI inside the Docker image, you can use the following single RUN command:

RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg  add - && apt-get update -y && apt-get install google-cloud-cli -y

If apt-key is not supported in the Docker image, use the following:

RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | tee /usr/share/keyrings/cloud.google.gpg && apt-get update -y && apt-get install google-cloud-sdk -y

RELATED TAGS

google cloud
ubuntu
debian
RELATED COURSES

View all Courses

Keep Exploring