Initialize the gcloud CLI

After you install the gcloud CLI, you can perform initial setup tasks by running gcloud init. The gcloud init command performs the following steps:

  • Authenticates with user account credentials, and then authorizes the gcloud CLI to access Google Cloud resources on your behalf. You can also do this separately with the gcloud auth login command.

  • Sets up a gcloud CLI configuration and sets core properties such as the active account, the current project, and if applicable, the default Compute Engine region and zone.

If you've already initialized the gcloud CLI, running gcloud init again lets you change existing settings or create a new configuration.

Initialize the gcloud CLI

To initialize the gcloud CLI:

  1. Run gcloud init:

    gcloud init

    If you're using a remote terminal session, add the --console-only flag. This flag provides the URL to the authentication and authorization flow instead of attempting to open it in your default browser.

    gcloud init --console-only
  2. Create or select a configuration if prompted.

    For new gcloud CLI installations, gcloud init creates a configuration named default for you and sets it as the active configuration. If you have existing configurations, gcloud init prompts you to choose between the following options:

    • Re-initialize the active configuration.
    • Switch to another configuration and re-initialize it.
    • Create a new configuration.
  3. Complete the authentication and authorization steps when prompted.

    If you have previously authorized access to Google Cloud, you might be prompted to sign in again and grant access in a web browser, or to select an existing account.

    If you used the --console-only flag and sign-in is required, copy and paste the provided authorization URL into another browser window and follow the prompts.

  4. Choose a Google Cloud project if prompted.

    If you only have access to one project—including the default project for your user account—gcloud init selects it for you.

    Otherwise, you can select a project from a list of projects on which you have the Owner, Editor, or Viewer roles. If you have access to more than 200 projects, you're prompted to enter a project ID, create a new project, or list projects.

  5. Choose a default Compute Engine zone if prompted. If you don't have the Compute Engine API enabled or you already have a default zone in your project-level metadata, this step is skipped.

View configuration properties

To view the properties set through the gcloud init command, use the gcloud config list command. The command returns an output similar to the following example:

[compute]
region = us-east1
zone = us-east1-b
[core]
account = dana@example.com
disable_usage_reporting = False
project = example-project

What's next