Installing and Configuring GCP SDK

This lesson discusses getting started with CLI.

Installing Google Cloud SDK

GCP also provides a command-line interface using the SDK. The CLI interface provides more functionality over GUI or a website. In fact, there are some tasks that cannot be accomplished using the website, and these tasks/functionalities need to be done via CLI only.

So, let’s see how to install and configure Google Cloud CLI.

Installation without Docker

There are multiple ways to install the SDK. The recommended way to install anything is to open up official documentation and look at the installation method for your system. The official documentation is always updated for installation. If you don’t have Docker and are willing to install it natively on the OS, feel free to use the Quickstart Installation guide for your OS and follow the steps for your systems.

If you want to use the Docker version of SDK, that’s also fine. Since Docker abstracts all the dependencies and works on all the systems, Docker is the quickest way to get started. However, you need to learn docker if you haven’t learned it yet.

If you want to know the basics to get started with Docker quickly, here is the Docker course.

Installation using Docker

  1. Pull the latest SDK image from the container repository using the following command.

docker pull gcr.io/google.com/cloudsdktool/cloud-sdk:latest

  1. Verify the image by running the following command.

docker run --rm gcr.io/google.com/cloudsdktool/cloud-sdk:latest gcloud version

The output will be similar to:

Google Cloud SDK 317.0.0
alpha 2020.10.30
app-engine-go 1.9.71
app-engine-java 1.9.82
app-engine-python 1.9.91
app-engine-python-extras 1.9.91
beta 2020.10.30
bigtable 
bq 2.0.62
cbt 0.9.0
cloud-datastore-emulator 2.1.0
cloud-firestore-emulator 1.11.9
cloud-spanner-emulator 1.1.1
core 2020.10.30
datalab 20190610
gsutil 4.54
kubectl 1.16.13
pubsub-emulator 0.1.2

That’s it. Only two steps to get started with the SDK using docker.

You can also start using gcloud on the ephemeral terminal given at the end of this lesson.

  • Type gcloud version to cross-check the installation.

Configuring Cloud SDK

To start using the Cloud SDK we need to configure it. The command gcloud init is used to configure the initial settings for the SDK.

Configuring Docker GCP SDK

While using Docker, the state or configuration is stored in the Docker volume.

  • docker run -ti --name gcloud-config gcr.io/google.com/cloudsdktool/cloud-sdk gcloud auth login

Once you’ve successfully completed authentication, credentials are preserved in the volume of the gcloud-config container. You need to pass this volume to execute authenticated gcloud commands.

  • docker run --rm --volumes-from gcloud-config gcr.io/google.com/cloudsdktool/cloud-sdk gcloud config list

Configuration without Docker

  • If you installed SDK without Docker, type, gcloud init

This will initialize the configuration steps starting from the login and setting up the default project.

root@educative:/# gcloud init
Welcome! This command will take you through the configuration of gcloud.

Your current configuration has been set to: [default]

You can skip diagnostics next time by using the following flag:
  gcloud init --skip-diagnostics

Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.                                                               
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).

You must log in to continue. Would you like to log in (Y/n)?  Y

Go to the following link in your browser:

    https://accounts.google.com/o/oauth2/auth?client_id=32555940559.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&code_challenge=NURRInX6Sabjgx4hh4Ml5D6T5ppTnYLa2HL0h485R3s&code_challenge_method=S256&access_type=offline&response_type=code&prompt=select_account


Enter verification code: )

If you are using an OS native shell/terminal, gcloud will open the default browser and ask you to log in. If not, a link is provided, and you need to open it in the browser and copy and paste the code into the terminal.

Get hands-on with 1200+ tech skills courses.