Quickstart for Debian and Ubuntu

This page shows how to install the Google Cloud SDK, initialize it, and run core gcloud commands from the command-line.

Before you begin

Make sure that your operating system is one of the following:

Create a Google Cloud Platform project, if you don't have one already.

Then, perform the following steps:

# Add the Cloud SDK distribution URI as a package source
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list

# Import the Google Cloud Platform public key
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -

# Update the package list and install the Cloud SDK
sudo apt-get update && sudo apt-get install google-cloud-sdk

Docker tip: If installing the Cloud SDK inside a Docker image, use a single RUN step instead:

RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg  add - && apt-get update -y && apt-get install google-cloud-sdk -y

Troubleshooting your installation

If you are unable to get latest updates due to an expired key, obtain the latest apt-get.gpg key file.

If your distribution's apt-key command does not support the --keyring argument run these commands instead:

# Add the Cloud SDK distribution URI as a package source
echo "deb http://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list

# Import the Google Cloud Platform public key
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

# Update the package list and install the Cloud SDK
sudo apt-get update && sudo apt-get install google-cloud-sdk

Initialize the SDK

Use the gcloud init command to perform several common SDK setup tasks. These include authorizing the SDK tools to access Google Cloud Platform using your user account credentials and setting up the default SDK configuration.

To initialize the SDK:

  1. Run the following at a command prompt:

    gcloud init
    

    Note: If you get an error related to the gcloud command not being found, refer to step 5 in the section above.

    Note: To prevent the command from launching a web browser, use gcloud init --console-only instead. To authorize without a web browser and non-interactively, create a service account with the appropriate scopes using the Google Cloud Platform Console and use gcloud auth activate-service-account with the corresponding JSON key file.

  2. Accept the option to log in using your Google user account:

    To continue, you must log in. Would you like to log in (Y/n)? Y
    
  3. In your browser, log in to your Google user account when prompted and click Allow to grant permission to access Google Cloud Platform resources.

  4. At the command prompt, select a Cloud Platform project from the list of those where you have Owner, Editor or Viewer permissions:

    Pick cloud project to use:
     [1] [my-project-1]
     [2] [my-project-2]
     ...
     Please enter your numeric choice:
    

    If you only have one project, gcloud init selects it for you.

  5. If you have the Google Compute Engine API enabled, gcloud init allows you to choose a default Compute Engine zone:

    Which compute zone would you like to use as project default?
     [1] [asia-east1-a]
     [2] [asia-east1-b]
     ...
     [14] Do not use default zone
     Please enter your numeric choice:
    

    gcloud init confirms that you have complete the setup steps successfully:

    gcloud has now been configured!
    You can use [gcloud config] to change more gcloud settings.
    
    Your active configuration is: [default]
    

Run core gcloud commands

Run these gcloud commands to view information about your SDK installation:

  1. To list accounts whose credentials are stored on the local system:

    gcloud auth list
    

    gcloud displays a list of credentialed accounts:

           Credentialed Accounts
    ACTIVE             ACCOUNT
    *                  example-user-1@gmail.com
                       example-user-2@gmail.com
    
  2. To list the properties in your active SDK configuration:

    gcloud config list
    

    gcloud displays the list of properties:

    [core]
    account = example-user-1@gmail.com
    disable_usage_reporting = False
    project = example-project
    
  3. To view information about your Cloud SDK installation and the active SDK configuration:

    gcloud info
    

    gcloud displays a summary of information about your Cloud SDK installation. This includes information about your system, the installed SDK components, the active user account and current project, and the properties in the active SDK configuration.

  4. To view information about gcloud commands and other topics from the command line:

    gcloud help
    

    For example, to view the help for gcloud compute instances create:

    gcloud help compute instances create
    

    gcloud displays a help topic that contains a description of the command, a list of command flags and arguments, and examples of how to use it.

What's next

  • Read the gcloud tool guide for an overview of the gcloud command-line tool, including a quick introduction to key concepts, command conventions, and helpful tips.
  • Read the gcloud reference guide for detailed pages on each gcloud command, including descriptions, flags, and examples, that you can use to perform a variety of tasks on Google Cloud Platform.
  • Install additional Cloud SDK APT packages.
Oliko tästä sivusta apua? Kerro mielipiteesi

Palautteen aihe:

Tämä sivu
Cloud SDK Documentation