How to Setup and Configure Google Cloud CLI or SDK

In this tutorial, we’ll explain how to Setup and Configure Google Cloud CLI or SDK on Linux/MAC. Assuming you have already created VM Instance in GCP.

Steps to Setup and Configure Google Cloud CLI or SDK

Step 1: Download SDK package from Google Cloud SDK

(OR) Run below command – replace el8 with el7 in the value for baseUrl

sudo tee -a /etc/yum.repos.d/google-cloud-sdk.repo << EOM
[google-cloud-sdk]
name=Google Cloud SDK
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el8-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
       https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOM

Step 2: Untar the download Google Cloud SDK

$ tar –xvf google-cloud-sdk-*

Step 3: Run the script to install SDK

./google-cloud-sdk/install.sh

Step 4: As per the requirement select the required option.
How to Setup and Configure Google Cloud CLI or SDK

Steps to Configure Google Cloud SDK

Follow mention simple steps to configure Google Cloud SDK

Step 1: First, you need to initialize the SDK with commands.

gcloud init

Step 2: Log in to Google account and process

To continue, you must log in. Would you like to login (Y/N)? Y

Step 3: Goto any of the web browser and log in to your Google Cloud account and allow permission to access Cloud service

Step 4: You will get prompted on command prompt and proceed with the initial configuration

Now Check Google CLI

To test you can run some of the gcloud CLI commands

Step 1: Credential account

$ gcloud auth list

Step 2: Now list the SDK configuration

$ gcloud config list

Step 3: Check the gcloud configuration info

$ gcloud info

Step 4: You can also check all the commands

$ gcloud help

Let’s take an example for Instance creation

Steps to create an Instance in Google Cloud using CLI

Step 1: Command to list images to launch Instance

$ gcloud compute images list

Step 2: Now create f1 micro Centos Instance with the following command

$ gcloud compute instances create sysadmin-dev-instance \

--image centos-7-v20180523 \

--image-project centos-cloud –set-machine-type f1-micro –zone us-central1-a

Step 3: Steps to connect instance via SSH

Follow the mentioned command to connect the instance via ssh.

$ gcloud compute ssh <instance-name>

The above command will automatically create ssh key in your ~/.ssh directory and connect to your instance

For Example:

gcloud compute ssh sysadmin-dev-instance

Steps to delete the Instance in Google Cloud

It is very easy to delete the instance using CLI, make sure your entry correct instance name or you may delete some other instance.

$ gcloud compute instance delete (instance name)

For Example

$ gcloud compute instances delete sysadmin-dev-instance

This is how to Setup and Configure Google Cloud CLI or SDK.


Thanks for reading this article, you’ll also like to read below articles.

Checklist for Pre and Post Linux Reboot

How to Mount Extra Disks On Google Cloud Engine