In this tutorial, we will learn to install Google Cloud SDK in Linux machines (Ubuntu, CentOS etc), but before we do that, we must know what Google Cloud SDK is & what prerequisites does the cloud SDK has.
Google Cloud SDK is used to manage the google cloud platform using the CLI, command-line interface of your system’s terminal. Google Cloud SDK is basically a collection of tools/commands like bq, gcloud, gsutil, etc for the management of our cloud resources. It supports Linux, Mac & Windows as well.
So for prerequisites, Google cloud SDK needs to have python installed on our Linux. It needs to have python version 2.7.9 or higher or Python 3.5 to 3.7. You can also refer to the following tutorials to install python on Ubuntu & on CentOS.
Recommended Read: Easy way to install AWS CLI on Linux
Also Read: Simple guide to install TERRAFORM on Linux
Install Google Cloud SDK on Ubuntu -Debian
For installing Google Cloud SDK on Ubuntu or Debian, we need to add google repository & then install it using apt-get. So run the following command to add the google SDK URL as package source,
$ 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
Next, we need to install the apt-transport-https package, if not already installed,
$ sudo apt-get install apt-transport-https ca-certificates gnupg
Now, import the google cloud public key with the following command,
$ curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
& now as the last step, we need to install the google cloud sdk,
$ sudo apt-get update && sudo apt-get install google-cloud-sdk
Now we have cloud SDK installed on our Ubuntu or Debian system, next we run the following command to configure the SDK,
$ gcloud init
Once you run the command, you would be asked to log in to your account, press 'y' to proceed. Then we will be given a long URL as the output on the screen,
Copy the URL & open in a web browser. We will then be asked to enter the GCP account details (username & password), upon successful authentication we will be given a verification code,
Paste this code to the terminal window & we will be logged in to Google-cloud-SDK on that system. Google init command will then ask to select the project, region, etc. Select those & we are ready to use the Google cloud sdk commands.
Install Google Cloud SDK on Redhat/CentOS/Fedora
Similar to how we did it for Ubuntu, we need to add the Google cloud repo on CentOS/RedHat/Fedora system with the following command,
$ 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-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOM
Now we can simply install cloud sdk,
$ yum install google-cloud-sdk
Now run the gcloud init command to configure the SDK,
$ gcloud init
Rest steps are the same as maintained above.
Install additional packages for Google Cloud SDK
There are many other packages that are not installed by default but can be installed manually later. Packages like,
- google-cloud-sdk-app-engine-python
- google-cloud-sdk-app-engine-python-extras
- google-cloud-sdk-app-engine-java
- google-cloud-sdk-app-engine-go
- google-cloud-sdk-bigtable-emulator
- google-cloud-sdk-cbt
- google-cloud-sdk-cloud-build-local
- google-cloud-sdk-datalab
- google-cloud-sdk-datastore-emulator
- google-cloud-sdk-firestore-emulator
- google-cloud-sdk-pubsub-emulator
- kubectl
To install any of these packages, we can run the following commands,
Ubuntu/Debian
$ sudo apt-get install google-cloud-sdk-app-engine-python
RedHat/CentOS/Fedora
$ sudo yum install google-cloud-sdk-app-engine-python
Install Google SDK on Linux
For other Linux distributions that are not based on Debian or Redhat, we can also use the install script to install SDK on them. There are separate scripts available for 32 & 64-bit machines, download them using the respective command mentioned below,
Linux 64 bit install script
$ wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-307.0.0-linux-x86_64.tar.gz
Linux 32 bit Install script
$ wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-307.0.0-linux-x86.tar.gz
Now extract the gz file with the following command,
$ tar -xvzf google-cloud-sdk-307.0.0-linux-x86_64.tar.gz
& now we need to run the install script located inside the extracted folder,
$ cd google-cloud-sdk
$ ./install.sh
Open the script has been completed, we can open a new terminal to use the installed sdk. To configure the sdk, execute the following command,
$ cd google-cloud-sdk
$ ./bin/gcloud init
Note :- Instances on Google Cloud come with Google cloud SDK installed by default.
So that’s it for our tutorial on the installation of Google Cloud sdk. Please feel free to send in any questions/queries, or suggestions using the comment box below.