Command-line tools are empowering: they deliver speed, control, traceability, scripting and automation capabilities to the developer’s workflow. Here are a few tips and tricks on how to start working with, and how to get more out of Google Cloud Platform’s command-line tools.

Simplified Tool Installation
For streamlined tool distribution, all Google Cloud Platform command-line tools are bundled in Google Cloud SDK, so you only need to obtain Cloud SDK to get command-line access to App Engine, Compute Engine, Cloud Storage, Cloud SQL, BigQuery and other products.

Here’s how to install Cloud SDK:

  • If you’re running on Windows, download Cloud SDK zip and launch install.bat script,
  • If you’re running on Linux or Mac OS run the following command in your shell/Terminal:
curl https://dl.google.com/dl/cloudsdk/release/install_google_cloud_sdk.bash | bash

When the installer completes, restart your shell/Terminal/Command Prompt window and you should be able to run the main Cloud SDK command-line tool, called gcloud.
.
Component Management
One of the new features installed with Cloud SDK is a component manager, accessible via gcloud components command group. The component manager allows you to add, remove and update Cloud Platform tools without ever needing to re-download the SDK.

Run gcloud components list to see the list of available or installed components, gcloud components update component-id to install or update a particular component or gcloud components --help for more information.

Tip: if you’re using more than one programming language for App Engine development, use Cloud SDK component manager to install multiple App Engine SDKs side-by-side. For example, if you wanted to add Python and Java support for App Engine, run gcloud components update gae-python gae-java.

Staying Up-to-Date
To ensure that you always have the latest versions of Cloud Platform tools, Cloud SDK will notify you if any updates are available when you run individual commands. For example, if Cloud SQL releases an update, the following message will be appended after running Cloud SQL commands:

$ gcloud sql instances list
my-developers-console-project:sql-instance

There are available updates for some Cloud SDK components. To install them, please run:
$ gcloud components update

You can then perform the update in place using the component manager by running gcloud components update, as described above.

Tip: if you want to stick with the current version of the tools that you have installed, you can disable these notifications by running gcloud config set --section component_manager disable_update_check.

Unified Authentication into the whole Google Cloud Platform
Google Cloud SDK provides a unified authentication model across all of the command-line tools. You only need to complete the authentication flow via gcloud auth login once, and you will be authenticated into all tools simultaneously.

Tip: Cloud SDK also allows you to use multiple accounts by repeating gcloud auth login flow. Run gcloud auth list to see all credentialed accounts, and gcloud config set account to set the active account.

Project Initialization and Push-to-Deploy
Every new project created on Google Developers Console now comes with a free private Git repository, where you can store your source code and use it for your App Engine app deployments via push-to-deploy.

To quickly initialize your local environment, run cloud init project-id. This command will set-up the version control system, clone the source code onto your machine and will set-up push-to-deploy, all in one command. Here’s a workflow example:


  1. Create “my-awesome-app” application in Google Developers Console.
  2. Install Cloud SDK and run gcloud init my-awesome-app.
  3. Change directory to my-awesome-app/default and add some code. (Have a look at some sample projects if you need inspiration.)
  4. Commit the code by running git commit -a -m “First commit for my awesome app” and deploy it by running git push origin master.
  5. Your app should now be serving live at https://my-awesome-app.appspot.com!

General Usage Tips
Command autocompletion

If you’re running on Mac or Linux and you’ve chosen to enable command-line autocompletion during Cloud SDK’s install, then you should be able to use the Tab key to complete the commands under gcloud in your shell or Terminal.

For example, typing “gclo + Tab + con + Tab + l + Tab” will expand to “gcloud config list“. Similarly, pressing the Tab key twice should show all possible options in ambiguous cases, e.g. typing “gclo + Tab + co + Tab + Tab” should show “config components”.

Tip: this works for flags too! Type “gcloud sql instances create - + Tab + Tab“ (don’t forget the dash at the end!) to see all possible flags that you can pass for a new Cloud SQL instance.

Interactive mode

To further simplify scripting and automation, Cloud SDK allows you to call various gcloud commands from Python scripts. To experiment with this, run gcloud interactive to start an interactive Python shell.

For example, to get the currently set default project from gcloud config list (without scraping the console output), run gcloud interactive to get into the interactive Python mode and paste the gcloud.config.list()[’core’][’project’] command. Python interpreter should return you the string containing the default project. You can then use a similar approach to get the currently set project from your Python scripts.

See the interactive mode documentation for more details.

Help and support
If you’re ever unsure about how to use one or another gcloud command, try appending “--help“ to the end of a command. This works at all command nesting levels, e.g.
  • gcloud --help
  • gcloud sql --help
  • gcloud sql backups --help
  • gcloud sql backups list --help
If you have any further questions post them on Stack Overflow using “gcloud” tag, send us a message at google-cloud-sdk@googlegroups.com (our discussions and support forum), or come and chat to us live on #gcloud channel at freenode IRC network.

Note that other Cloud Platform command-line tools are still being integrated into gcloud, so stay tuned and check back our blog soon for more good news about Cloud SDK!

-Posted by Manfred Zabarauskas, Product Manager