0
0
GCPcloud~5 mins

Installing and initializing gcloud in GCP - Step-by-Step CLI Walkthrough

Choose your learning style9 modes available
Introduction
To work with Google Cloud services from your computer, you need a tool called gcloud. Installing and setting it up lets you control your cloud projects easily from the command line.
When you want to create or manage Google Cloud resources from your laptop or server.
When you need to deploy applications to Google Cloud.
When you want to check the status of your cloud services quickly.
When you want to switch between different Google Cloud projects.
When you want to run scripts that automate cloud tasks.
Commands
This command downloads and runs the Google Cloud SDK installer script to install the gcloud tool on your system.
Terminal
curl https://sdk.cloud.google.com | bash
Expected OutputExpected
Welcome to the Google Cloud SDK! This script will install all the gcloud command line tools. You will be prompted to update your PATH and enable command completion. Starting installation... Installation complete.
This command restarts your shell so that the changes to your PATH take effect and you can use gcloud immediately.
Terminal
exec -l $SHELL
Expected OutputExpected
No output (command runs silently)
This command starts the setup process to log in to your Google account and select a default project to work with.
Terminal
gcloud init
Expected OutputExpected
Welcome! This command will take you through the configuration of gcloud. Pick configuration to use: [1] Re-initialize this configuration [2] Create a new configuration Enter your numeric choice: 1 You are logged in as: user@example.com Pick cloud project to use: [1] my-first-project [2] my-second-project Enter your numeric choice: 1 Your gcloud CLI is now configured.
This command shows the current settings of gcloud, including which project and account are active.
Terminal
gcloud config list
Expected OutputExpected
[core] account = user@example.com project = my-first-project
Key Concept

If you remember nothing else, remember: installing gcloud and running 'gcloud init' sets up your access to Google Cloud from your computer.

Common Mistakes
Not restarting the shell after installation
The system does not recognize the gcloud command because the PATH was not updated in the current session.
Run 'exec -l $SHELL' or close and reopen your terminal to refresh the PATH.
Skipping 'gcloud init' after installation
Without initialization, gcloud has no account or project set, so commands will fail or ask for configuration every time.
Always run 'gcloud init' to log in and select your default project.
Summary
Install gcloud SDK by downloading and running the installer script.
Restart your shell to update the PATH and enable gcloud commands.
Run 'gcloud init' to log in and select your Google Cloud project.
Use 'gcloud config list' to verify your current configuration.