What is gcloud and how to install it on Windows, MacOS and Linux?

Google Cloud is one of the leading cloud computing platforms and did you know that they offer gcloud CLI for infrastructure management and automation?

Imagine you want to view your GCP resources, provision your infrastructure without logging into the Google Cloud Console. gcloud can help in many ways.

What is gcloud?

gcloud is a desktop command line tool for the Google Cloud Platform. You can literally do everything with gcloud that you do on the cloud console.

To take a look at a brief introduction, there is a list of the most commonly used commands with their structure, follow the gcloud cheat sheet or see the official cheat sheet .

You can control many things as shown below.

  • Computing engine (VM)
  • Cloud DNS
  • Kubernetes Engine
  • Cloud SQL
  • Cloud computing
  • Cloud deployment
  • Deploying App Engine Applications
  • Authentication Management
  • Set up local configuration

and much more…

gcloud is a cross-platform SDK that you can install on your favorite OS like Windows, macOS, Linux, etc.

Installing gcloud on linux

Python is a prerequisite for installing gcloud, so make sure you install it on your machine or server. You can refer to this Python Installation Guide if you need to install it.

Example for 64-bit

curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-342.0.0-linux-x86_64.tar.gz

and for 32-bit

curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-342.0.0-linux-x86.tar.gz
  • Unzip the downloaded file which will create a new folder called google-cloud-sdk.
  • Run the install.sh file
./google-cloud-sdk/install.sh
  • Restart the terminal for the changes to take effect.
  • Let's initialize the gcloud SDK by running the command below.
gcloud init

Installing gcloud on Windows

As usual, things are much easier on Windows, just download the Windows Cloud SDK Installer and run it.

Or, if you prefer terminal methods, open a PowerShell terminal (not CMD) and run the following PowerShell commands:

(New-Object Net.WebClient).DownloadFile("https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe", "$env:TempGoogleCloudSDKInstaller.exe")& $env:TempGoogleCloudSDKInstaller.exe

2- The installer signed by Google LLC will suggest the following steps, follow them.

Optionally, you can enable screen reader mode for easier screen reading, check the Enable screen reader mode box. For more information about Cloud SDK screen readers, see the Accessibility Guide .

3. Since the Cloud SDK requires Python, you must install it and any other required dependencies. Supported versions: Python 3 (3.5 to 3.8 preferred) and Python 2 (2.7.9 or higher). This means that you can use an existing Python installation despite the SDK currently using Python 3 by default. This can be done by unchecking "Install bundled Python".

4- Now that the installation is complete, you will be presented with several options to choose from:

Be sure to select these:

  • Launch the Google Cloud SDK wrapper
  • Run gcloud initialization

The SDK terminal window will now appear and automatically execute the gcloud init command.

5- So this is the default setting; it does not contain the App Engine extensions required to deploy the app using gcloud commands. You can install these components in the Cloud SDK Component Manager.

Troubleshooting:

  • If you encounter an installation error due to the find command not being recognized, make sure your PATH environment variable is set to include the folder containing find. Should be: C:WINDOWSsystem32;.
  • If you have just uninstalled the Cloud SDK, you will need to restart your computer to install the new Cloud SDK.

For macOS

1- As with any other OS, for macOS you will also need Python for the SDK. Versions supported: Python 3 (3.5 to 3.8 preferred) and Python 2 (2.7.9 or higher). Alternatively, you can opt for 64-bit macOS with a packaged Python installation.

Run the following to check your current Python version:

python -V

If you need more information about choosing and configuring a Python interpreter, visit the gcloud thread launcher .

2- There are four packages, choose to download the one that suits your OS from the following:

Run uname -m from the command line to determine the appropriate hardware name for the machine.

3- Now unzip the file to whatever path you want in your file system, this is recommended in your home directory. To do this on macOS, simply open the downloaded .tar.gz archive file in the desired location.

If you want to replace an existing installation, delete the existing google-cloud-sdk directory and extract the archive to the same location. If you already have an existing installation and want to replace it, simply remove the old google-cloud-sdk directory and then extract the new package to the same location.

4- Optionally, you can use the install script to install additional Cloud SDK tools in the same PATH. Also, if you want, you can contribute command completion to collect usage statistics and command completion for your shell.

Execute this script exactly from the root of the folder where the SDK was extracted from:

./google-cloud-sdk/install.sh

You can also do this non-interactively using a script or by specifying settings in the form of flags by running this command:

./google-cloud-sdk/install.sh --help

To run an installation script with screen reader enabled:

./google-cloud-sdk/install.sh --screen-reader=true

Now restart the terminal for the changes to take effect.

6- To initialize SDK run gcloud init:

./google-cloud-sdk/bin/gcloud init

Optional:

  • Install additional SDK components from the Component Manager.
  • Install the latest version of Google Cloud Client Libraries and libraries for supported languages.

Using Gcloud

The instructions above install the Cloud SDK components by default, including the gcloud, gsutil, and bq command line tools.

To manage and use the installation after installing the Cloud SDK, use the commands in the gcloud component commands group. This includes viewing installed components, installing and uninstalling components, and updating the Cloud SDK to a newer version or even switching to a specific version.

To install additional components, use the gcloud components install command or install the appropriate deb or RPM packages.

Gcloud for mobile

To use gcloud on a smart mobile phone, please install Google Cloud Console.

For iPhone: Google Cloud Console| App Store .

For Android: Google Cloud Console‏ | Google games .

Just open the black shell icon.

Summary

With these instructions, whether you want to use gcloud, in the browser, on your computer, or just on your smartphone. Whatever your operating system, it's clear that the whole process is fairly easy to implement.

Related posts