--- title: "How to Install and Use the gcloud CLI on Ubuntu 24.04" description: "Install the Google Cloud CLI on Ubuntu 24.04 from the official APT repository, log in from a headless server, set up projects and manage Cloud Storage and VMs." category: "Cloud Integration" language: en source: https://cubepath.com/docs/cloud-integration/google-cloud-sdk-installation-and-usage updated: 2026-09-25 --- # How to Install and Use the gcloud CLI on Ubuntu 24.04 The Google Cloud CLI (`gcloud`, formerly called the Google Cloud SDK) is the command-line tool for Google Cloud Platform: it manages projects, Compute Engine VMs, Cloud Storage buckets, IAM and almost every other GCP service. In this tutorial you will install it on an Ubuntu 24.04 server from Google's official APT repository, authenticate from a machine without a browser, configure a default project, and use it to move files to Cloud Storage and manage a VM. ## Prerequisites To follow this guide you need: - A server running Ubuntu 24.04 LTS, for example a CubePath VPS. - A non-root user with `sudo` privileges. - A Google Cloud account with at least one project and billing enabled (required for Compute Engine and Cloud Storage). - A computer with a web browser, used once to approve the login. ## Step 1 - Adding the Google Cloud APT repository Google publishes signed packages for Debian and Ubuntu. Installing from the repository means `apt upgrade` keeps `gcloud` up to date together with the rest of the system. Install the tools needed to fetch the signing key: ```bash sudo apt update sudo apt install -y ca-certificates curl gnupg ``` Download Google's signing key and store it in `/etc/apt/keyrings`: ```bash sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/cloud.google.gpg ``` Add the repository, pointing it at that key with `signed-by`: ```bash echo "deb [signed-by=/etc/apt/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee /etc/apt/sources.list.d/google-cloud-sdk.list ``` ## Step 2 - Installing the gcloud CLI Refresh the package index and install the `google-cloud-cli` package: ```bash sudo apt update sudo apt install -y google-cloud-cli ``` Verify the installation: ```bash gcloud version ``` ```output Google Cloud SDK 5xx.0.0 bq 2.1.x bundled-python3-unix 3.12.x core 2026.xx.xx gcloud-crc32c 1.0.0 gsutil 5.xx ``` Because the CLI is managed by APT, the `gcloud components install` and `gcloud components update` commands are disabled. Extra components are separate packages instead. For example, if you work with GKE clusters: ```bash sudo apt install -y kubectl google-cloud-cli-gke-gcloud-auth-plugin ``` ## Step 3 - Authenticating from a headless server A server usually has no browser, so ask `gcloud` to print the login URL instead of opening one: ```bash gcloud auth login --no-launch-browser ``` The command prints a long URL. Open it on your own computer, sign in with your Google account, approve the access request and copy the verification code that Google shows. Paste it back into the terminal: ```output Enter authorization code: 4/0Axxxxxxxxxxxxxxxxxxxxxx You are now logged in as [you@example.com]. ``` List the credentialed accounts to confirm: ```bash gcloud auth list ``` ```output Credentialed Accounts ACTIVE ACCOUNT * you@example.com ``` > Note: `gcloud auth login` authorizes the `gcloud` tool itself. If you also run applications that use Google Cloud client libraries on this server, they look for Application Default Credentials, which you set separately with `gcloud auth application-default login --no-launch-browser` or with a service account key (Step 7). ## Step 4 - Setting the default project and region Most commands need a project. List the projects your account can access: ```bash gcloud projects list ``` ```output PROJECT_ID NAME PROJECT_NUMBER your-project-id My Project 123456789012 ``` Set the default project, and a default Compute Engine region and zone so you do not have to pass `--zone` on every command: ```bash gcloud config set project your-project-id gcloud config set compute/region europe-west1 gcloud config set compute/zone europe-west1-b ``` Check the active configuration: ```bash gcloud config list ``` ```output [compute] region = europe-west1 zone = europe-west1-b [core] account = you@example.com project = your-project-id ``` APIs are disabled by default in new projects. Enable the ones used in this tutorial: ```bash gcloud services enable compute.googleapis.com storage.googleapis.com ``` ## Step 5 - Working with Cloud Storage Use the `gcloud storage` command group for buckets and objects. It replaces the older `gsutil` tool, which is still installed but no longer recommended for new scripts. Bucket names are global across all of Google Cloud, so pick a unique name. Create a bucket in the same region as your default: ```bash gcloud storage buckets create gs://your_bucket_name --location=europe-west1 --uniform-bucket-level-access ``` Upload a file and a whole directory: ```bash gcloud storage cp /etc/hostname gs://your_bucket_name/ gcloud storage cp --recursive /var/log/nginx gs://your_bucket_name/logs/ ``` Keep a directory in sync with a bucket prefix. `rsync` only transfers new or changed files; `--delete-unmatched-destination-objects` also removes objects that no longer exist locally, so leave it out if the bucket should keep deleted files: ```bash gcloud storage rsync --recursive /var/www gs://your_bucket_name/www ``` List the bucket contents with sizes: ```bash gcloud storage ls --long --readable-sizes gs://your_bucket_name/ ``` ```output 9.00B 2026-09-25T10:02:11Z gs://your_bucket_name/hostname gs://your_bucket_name/logs/ gs://your_bucket_name/www/ TOTAL: 1 objects, 9 bytes (9.00B) ``` Download an object back to the server: ```bash gcloud storage cp gs://your_bucket_name/hostname /tmp/hostname ``` ## Step 6 - Managing Compute Engine VMs Create a small Ubuntu 24.04 VM. Canonical publishes its images in the `ubuntu-os-cloud` project, with separate image families per architecture: ```bash gcloud compute instances create my-vm \ --machine-type=e2-small \ --image-family=ubuntu-2404-lts-amd64 \ --image-project=ubuntu-os-cloud \ --boot-disk-size=20GB ``` List your instances and their IP addresses: ```bash gcloud compute instances list ``` ```output NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS my-vm europe-west1-b e2-small 10.132.0.2 34.xx.xx.xx RUNNING ``` Connect over SSH. `gcloud` generates a key pair on first use and publishes the public key to the project metadata: ```bash gcloud compute ssh my-vm ``` Stop the VM when you do not need it, and delete it when you are done so it stops generating costs: ```bash gcloud compute instances stop my-vm gcloud compute instances delete my-vm ``` ## Step 7 - Using a service account for automation Your personal login is fine for interactive work, but unattended jobs such as a nightly backup should use a service account with only the permissions they need. Create one: ```bash gcloud iam service-accounts create backup-agent --display-name="Backup agent" ``` Grant it write access to objects in your bucket only, instead of a project-wide role: ```bash gcloud storage buckets add-iam-policy-binding gs://your_bucket_name \ --member="serviceAccount:backup-agent@your-project-id.iam.gserviceaccount.com" \ --role="roles/storage.objectUser" ``` A server outside Google Cloud needs a key file to act as the service account. Create it in a directory only your user can read: ```bash mkdir -p ~/.config/gcloud/keys && chmod 700 ~/.config/gcloud/keys gcloud iam service-accounts keys create ~/.config/gcloud/keys/backup-agent.json \ --iam-account=backup-agent@your-project-id.iam.gserviceaccount.com chmod 600 ~/.config/gcloud/keys/backup-agent.json ``` > Important: Many organizations block key creation with the `iam.disableServiceAccountKeyCreation` organization policy. If the command fails with a policy error, ask your administrator for an exception or use Workload Identity Federation instead. Treat the key like a password and delete it from IAM when it is no longer used. Rather than replacing your personal login, keep the service account in its own named configuration (see Step 8), then activate the key there: ```bash gcloud config configurations create backup gcloud auth activate-service-account --key-file="$HOME/.config/gcloud/keys/backup-agent.json" gcloud config set project your-project-id ``` ## Step 8 - Switching between configurations Named configurations store a set of properties (account, project, region) that you can switch between, which is useful when you manage several projects. List them: ```bash gcloud config configurations list ``` ```output NAME IS_ACTIVE ACCOUNT PROJECT COMPUTE_DEFAULT_ZONE COMPUTE_DEFAULT_REGION backup True backup-agent@your-project-id.iam.gserviceaccount.com your-project-id default False you@example.com your-project-id europe-west1-b europe-west1 ``` Switch back to your personal configuration: ```bash gcloud config configurations activate default ``` For a single command, use `--configuration` without changing the active one, which is what you would put in a cron job or systemd unit: ```bash gcloud storage ls gs://your_bucket_name/ --configuration=backup ``` ## Troubleshooting **`The required property [project] is not currently set`**: no default project in the active configuration. Run `gcloud config set project your-project-id` or pass `--project`. **`API [compute.googleapis.com] not enabled on project`**: enable it with `gcloud services enable compute.googleapis.com` and wait a minute before retrying. **`403 ... does not have storage.objects.create access`**: the active account lacks the IAM role for that bucket. Check which account is active with `gcloud auth list` and review bindings with `gcloud storage buckets get-iam-policy gs://your_bucket_name`. **`gcloud components update` says the component manager is disabled**: this is expected on an APT installation. Update with `sudo apt update && sudo apt install --only-upgrade google-cloud-cli` instead. ## Conclusion You installed the gcloud CLI from Google's APT repository, logged in from a headless server, configured a default project and region, and used it to manage Cloud Storage objects and a Compute Engine VM, with a separate service account for automation. Next, you could schedule `gcloud storage rsync` with a systemd timer to back up this server, explore `gcloud compute firewall-rules` to control VM traffic, or learn the `--format` and `--filter` flags to script against `gcloud` output.