0
0
GcpHow-ToBeginner · 3 min read

How to Install gcloud CLI in GCP: Step-by-Step Guide

To install the gcloud CLI on a Google Cloud Platform (GCP) virtual machine, use the official installation script by running curl https://sdk.cloud.google.com | bash. After installation, restart your shell and run gcloud init to configure your CLI with your GCP account.
📐

Syntax

The main command to install the gcloud CLI uses a curl command to download and run the installation script. After installation, you initialize the CLI with gcloud init.

  • curl https://sdk.cloud.google.com | bash: Downloads and runs the installer script.
  • exec -l $SHELL: Restarts your shell to update environment variables.
  • gcloud init: Starts the setup wizard to log in and configure your CLI.
bash
curl https://sdk.cloud.google.com | bash
exec -l $SHELL
gcloud init
💻

Example

This example shows how to install the gcloud CLI on a Linux-based GCP VM, restart the shell, and initialize the CLI for your account.

bash
curl https://sdk.cloud.google.com | bash
exec -l $SHELL
gcloud init
Output
Welcome to the Google Cloud SDK! Your current Cloud SDK version is: x.y.z ... (installation progress messages) ... Your shell has been updated to use the Google Cloud SDK. You must now restart your shell. Pick configuration to use: [1] Re-initialize this configuration [2] Create a new configuration Please enter your numeric choice: 2 Enter configuration name: [default] You are now logged in as: user@example.com Your current project is: my-project-id You can change it using: $ gcloud config set project PROJECT_ID For more information, run: $ gcloud help
⚠️

Common Pitfalls

Common mistakes when installing gcloud CLI include:

  • Not restarting the shell after installation, causing commands to not be found.
  • Running the installer without internet access, which will fail.
  • Not running gcloud init to authenticate and configure the CLI.
  • Using outdated installation methods instead of the official script.
bash
curl https://sdk.cloud.google.com | bash
# Missing shell restart
# exec -l $SHELL  # This step is required

gcloud init  # This will fail if shell is not restarted
📊

Quick Reference

Summary tips for installing gcloud CLI:

  • Always use the official installation script from https://sdk.cloud.google.com.
  • Restart your shell after installation to update your environment.
  • Run gcloud init to log in and set your default project.
  • Check your installation with gcloud --version.

Key Takeaways

Use the official script with curl to install the gcloud CLI quickly and safely.
Restart your shell after installation to make the gcloud command available.
Run gcloud init to authenticate and configure your CLI for your GCP projects.
Avoid skipping steps like shell restart or initialization to prevent errors.
Verify installation with gcloud --version to confirm success.