How to install Google Cloud CLI on Debian/Ubuntu?
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-httppackage 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-sdkrepo 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-keycommand supports the--keyringargument:
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-keycommand does not support the--keyringargument:
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
Unlock your potential: Google Cloud CLI installation series, all in one place!
To continue your exploration of Google Cloud CLI installation, check out our series of Answers below:
How to install Google Cloud CLI on macOS?
Step-by-step instructions for installing Google Cloud CLI on macOS.How to install Google Cloud CLI on Windows?
Learn how to set up Google Cloud CLI on Windows for seamless cloud interactions.How to install Google Cloud CLI on Debian/Ubuntu?
Get the necessary commands to install Google Cloud CLI on Debian/Ubuntu Linux distributions.How to install Google Cloud CLI on Linux?
Explore the process of setting up Google Cloud CLI on Linux systems for command-line cloud access.
Free Resources