Cloud and deployment · Beginner · 13 min
Set up the gcloud CLI with named configurations for each project
By Padding · Updated 18 Nov 2026
Ubuntu 26.04 or macOS · Google Cloud CLI 594.0.1
You will have Google Cloud CLI 594.0.1 installed from Google's signed apt repository, with a personal and a work configuration that each carry their own account, project and region, and a clear rule for when to switch and when to use application-default credentials.
On this page
Every gcloud command runs against an account, a project and usually a region. If you keep one set of those and change it with gcloud config set project whenever you move between jobs, sooner or later a command meant for your side project lands in your employer's production project. Nothing in the output warns you; it just works, in the wrong place.
Named configurations fix that. A configuration is a small file holding a set of properties: which Google account to use, which project, which default region. You create one per context, switch between them on purpose, and can see at any moment which one is in charge.
In this tutorial you install Google Cloud CLI 594.0.1, create a personal and a work configuration, sign in to each, and practise the three ways of choosing one. The last steps cover application-default credentials, which are a separate thing that trips people up, and removing a configuration you no longer need. Commands are for Ubuntu 26.04; the install step also covers macOS, and everything after it is the same on both.
Step 1 · Install gcloud from Google's apt repository
Google publishes the CLI in its own apt repository, signed with its own key. You save that key to a dedicated keyring and tell apt to trust it for this repository only, using signed-by. That way the key cannot vouch for packages from any other source.
On Ubuntu, install the tools the setup needs, then save Google's key:
sudo apt update
sudo apt install -y ca-certificates gnupg curl
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpgAdd the repository, pointing signed-by at that keyring. Using tee without -a means running this twice leaves one line, not two:
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee /etc/apt/sources.list.d/google-cloud-sdk.listInstall version 594.0.1. Pinning the version here keeps your setup the same as this tutorial; leave off =594.0.1-0 to take the newest. The package is a large download, so on prepaid or metered mobile data, run it on Wi-Fi:
sudo apt update
sudo apt install -y google-cloud-cli=594.0.1-0
gcloud --versionBecause the CLI comes from an apt repository, sudo apt upgrade keeps it up to date from now on. The package does not include kubectl; if you need it later, install kubectl from the same repository.
On macOS, Google ships a tar archive per processor type. uname -m prints arm64 on Apple silicon and x86_64 on Intel Macs; download the matching archive, unpack it in your home folder and run the installer:
cd ~
curl -fLO https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-594.0.1-darwin-arm.tar.gz
tar -xf google-cloud-cli-594.0.1-darwin-arm.tar.gz
./google-cloud-sdk/install.shOn an Intel Mac, replace darwin-arm with darwin-x86_64 in both file names. The installer asks whether to add gcloud to your PATH and turn on command completion; answer Y, then open a new terminal. This copy does not update itself through any package manager, so run gcloud components update from time to time.
Check it worked
gcloud --version prints Google Cloud SDK 594.0.1 on its first line, followed by a few bundled components such as bq and gsutil (the exact list varies). On Ubuntu, cat /etc/apt/sources.list.d/google-cloud-sdk.list shows a single line with signed-by=/usr/share/keyrings/cloud.google.gpg in it.
Step 2 · See what gcloud starts with
Before adding anything, look at the configuration gcloud already has and where it keeps its files:
gcloud config configurations list
gcloud info --format='value(config.paths.global_config_dir)'gcloud begins with one configuration called default. There is nothing special about it; it exists so the CLI has somewhere to store properties before you create your own. On a fresh install it has no account and no project. If you have used gcloud before, the ACCOUNT and PROJECT columns show what every command currently uses.
The second command prints the folder that holds everything: ~/.config/gcloud on Linux and macOS. Each configuration is a file inside configurations/ in that folder, and a file called active_config holds the name of the one in charge.
Check it worked
The list shows a table with columns including NAME, IS_ACTIVE, ACCOUNT and PROJECT, plus the default zone and region, with exactly one row marked True under IS_ACTIVE. Note which configuration that is, and what project it points at, if any.
Step 3 · Create a personal configuration
Create a configuration for your own projects. create also makes it the active one:
gcloud config configurations create personalNow set its properties. Replace you@gmail.com with your own Google account and my-side-project-123 with your project's ID (the ID, not the display name; the console shows both on the project picker):
gcloud config set account you@gmail.com
gcloud config set project my-side-project-123
gcloud config set run/region africa-south1Because you have not signed in yet, gcloud warns that it cannot check you have access to the project. That is expected; the property is still saved, and the sign-in in a later step makes the check work.
run/region is the default region for Cloud Run. Compute Engine has its own default, compute/region, but gcloud checks that value against the Compute Engine API before saving it, and refuses it until the account is signed in. You set it after the sign-in step.
africa-south1 is Johannesburg, the Google Cloud region on the African continent, and the closest one for users across Southern and East Africa. Not every product is offered in every region, and prices differ between regions: Cloud Run, for example, runs in both africa-south1 and europe-west1, but africa-south1 is in its higher price tier. Check the product's own locations page before you build on a region. europe-west1 (Belgium) is a common choice for users in West and North Africa and in Europe.
Check it worked
gcloud config listThe output has a [core] section with your account and project, plus a [run] section with the region. On the last line it says Your active configuration is: [personal].
Step 4 · Create a work configuration without switching to it
For the second configuration, use --no-activate so you stay in personal while you build it. Then name the target configuration on each set with --configuration. Replace the account and project ID with your work ones:
gcloud config configurations create work --no-activate
gcloud config set account you@company.example --configuration=work
gcloud config set project company-web-prod --configuration=work
gcloud config set run/region europe-west1 --configuration=workSetting properties this way means you never have the work project active by accident while you are still typing.
Check it worked
gcloud config configurations list
gcloud config configurations describe workThe list now includes personal and work, alongside default. personal is still the one marked True. describe work prints the work account, company-web-prod and europe-west1 under properties.
Step 5 · Sign in once per account
Configurations hold the name of an account, not its credentials. gcloud keeps credentials in a separate store, one entry per account, and every configuration that names that account shares it. So you sign in once for each account, not once for each configuration.
Sign in to your personal account while personal is active:
gcloud auth login you@gmail.comA browser opens on Google's sign-in page. Choose the account, approve the request, and return to the terminal. If you are on a machine with no browser, for example over SSH, add --no-launch-browser: gcloud prints a link to open on your phone or laptop and asks you to paste back the code it shows.
Then sign in to the work account, naming the work configuration so the login updates that one:
gcloud auth login you@company.example --configuration=workgcloud auth login writes the account it signed in with into the configuration it ran in. If you pick a different account in the browser than the one you set, the configuration now names that account instead, so look at the result.
Now that both accounts are signed in, set the Compute Engine default region in each configuration:
gcloud config set compute/region africa-south1 --configuration=personal
gcloud config set compute/region europe-west1 --configuration=workIf the Compute Engine API is not turned on in a project yet, gcloud prints a warning that it skipped the check and saves the region anyway.
Check it worked
gcloud auth list
gcloud projects describe my-side-project-123 --format='value(projectId,lifecycleState)'gcloud auth list lists both accounts under Credentialed Accounts, with an asterisk next to you@gmail.com, the account of the active configuration. projects describe prints the project ID and ACTIVE; a permission error here means the account and project in personal do not match.
Step 6 · Choose a configuration three ways
There are three ways to pick a configuration, from longest-lasting to shortest:
gcloud config configurations activate NAMEchanges the active configuration for every terminal, and it stays changed after you close them.CLOUDSDK_ACTIVE_CONFIG_NAME=NAMEoverrides that for one terminal, until you close it or unset the variable.--configuration=NAMEoverrides both for one command.
Try each. Activate work, then go back to personal:
gcloud config configurations activate work
gcloud config get project
gcloud config configurations activate personal
gcloud config get projectSet the variable for this terminal only, then let a flag win over it for a single command:
export CLOUDSDK_ACTIVE_CONFIG_NAME=work
gcloud config get project
gcloud config get project --configuration=personal
unset CLOUDSDK_ACTIVE_CONFIG_NAMEA habit that keeps production safe: leave personal as the active configuration, and reach work projects with the variable or the flag. If you use direnv, put export CLOUDSDK_ACTIVE_CONFIG_NAME=work in an .envrc file in your work repository's folder, so the right configuration follows you into that folder and no further. For commands that change or delete things, type --configuration=work out in full, so the choice is visible in your shell history.
Check it worked
The first block prints company-web-prod, then my-side-project-123. The second block prints company-web-prod (from the variable), then my-side-project-123 (the flag wins). Afterwards, gcloud config configurations list still marks personal as active, because neither the variable nor the flag changes the saved choice.
Step 7 · Use application-default credentials only where a library needs them
gcloud's own login is for gcloud. Code that uses Google's client libraries, such as a Python script with google-cloud-storage or Terraform's Google provider, looks for a different thing: application-default credentials, usually shortened to ADC. You create those with a separate command:
gcloud auth application-default loginTwo things about ADC matter here:
- It is not tied to a configuration. There is one ADC file per user,
application_default_credentials.jsonin the gcloud folder, and it belongs to whichever account you signed in with last. Switching toworkchanges the account gcloud uses but does not change what your Python script uses. - It holds a refresh token. Anyone who can read that file can act as you. Do not copy it into a project folder, a container image or a backup you share.
So create ADC only on a machine where you run such code, and sign it in with the account that code should use. If a library complains that there is no quota project, set one that matches; replace the ID with the project your code works in:
gcloud auth application-default set-quota-project my-side-project-123When you no longer run that code on this machine, remove the credentials:
gcloud auth application-default revokeCheck it worked
ls ~/.config/gcloudBefore you run application-default login, the folder has configurations and active_config but no application_default_credentials.json. After it, the file appears; after revoke, it is gone again. Your named configurations are untouched either way.
Step 8 · Remove a configuration you no longer need
When a contract or side project ends, delete its configuration so it cannot be used by mistake. Practise on a throwaway one first:
gcloud config configurations create old-client --no-activate
gcloud config configurations delete old-clientgcloud lists what it will delete and asks you to confirm; press Y. You cannot delete the active configuration, so activate another one first if you need to delete the one you are in. Deleting a configuration removes only its file; the account's sign-in stays in gcloud's credential store. To remove that as well, run gcloud auth revoke followed by the account's email address.
Check it worked
gcloud config configurations listThe list still shows personal and work, with no old-client row.
Next steps
- Deploy a service with the
personalconfiguration in /tutorials/deploy-a-container-to-google-cloud-run. - Give each project only the access it needs in /tutorials/grant-least-privilege-access-in-google-cloud-iam.
- Set up the same separation for AWS in /tutorials/set-up-the-aws-cli-with-sso-and-named-profiles.
Related tutorials
- How to Deploy a Container to Google Cloud RunYou will package a small Node.js 26 web service with a Dockerfile, deploy it to Google Cloud Run with one gcloud command, cap how far it can scale, roll back to an earlier revision, and delete every resource the deploy created.
- Set up the AWS CLI v2 with IAM Identity Center sign-in and named profilesYou will have AWS CLI 2.42.4 installed from a signature-checked bundle, signing in through IAM Identity Center with separate dev and prod profiles and no long-lived access keys on your machine.
- Grant least-privilege access in Google Cloud with IAM roles and service accountsYou will give one Cloud Run service its own service account that can read exactly one Secret Manager secret, test that access by impersonation instead of a key, add a grant that expires on its own, and review who can reach the secret.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials