Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

install gcloud just once

It seems I have to install gcloud every time I want to use it. Is there a way to install it and just use which account I want to use it with?

Env: Mac OSX 12.4

Thank you.

0 1 4,153
1 REPLY 1

In order to install Cloud SDK on a Mac OS system, you could follow the Install the Google Cloud CLI quickstart. Here is a list of simplified steps taken from the quickstart:

Installing the latest gcloud CLI version

  1. Confirm that you have a supported version of Python (run python3 -V from a command line)
  2. Download one of the following (check the official documentation to get the latest version):
    Note: To determine your machine hardware name, run uname -m from a command line.
    1. Extract the archive to any location on your file system (preferably your Home directory).
    2. Run the script (from the root of the folder you extracted in the last step) using this command:

 

./google-cloud-sdk/install.sh

 

    1. Open a new terminal so that the changes take effect.
    2. To initialize the gcloud CLI, run gcloud init:

 

./google-cloud-sdk/bin/gcloud init

 

Initializing the gcloud CLI

Use the gcloud init command to perform several common gcloud CLI setup tasks. These include authorizing the gcloud CLI to access Google Cloud using your user account credentials and setting up the default configuration.

  1. Initialize the gcloud CLI:

 

 

gcloud init

 

  1. Accept the option to log in using your Google user account:
To continue, you must log in. Would you like to log in (Y/n)? Y
  1. In your browser, log in to your Google user account when prompted and click Allow to grant permission to access Google Cloud resources.
  2. At the command prompt, select a Google Cloud project from the list of projects where you have Owner, Editor or Viewer permissions:
Pick cloud project to use:
[1] [my-project-1]
[2] [my-project-2]
...
Please enter your numeric choice:
  1. If you only have one project, gcloud init selects it for you.
    gcloud init confirms that you have completed the setup steps successfully:
gcloud has now been configured!
You can use [gcloud config] to change more gcloud settings.
Your active configuration is: [default]

Now the gcloud SDK tools are successfully installed on your macOS, and you can use it to manage all the resources from CLI.

Then, if you want to have multiple configurations (such as account, project-ID, etc) and switch between them, you could check the Managing gcloud CLI configurations documentation:

Multiple configurations

The single default configuration is suitable for many use cases. However, you can also create additional configurations and switch between them as required using gcloud config configurations activate.

Creating a configuration

To create a configuration, run gcloud config configurations create:

 

gcloud config configurations create [NAME]

 

You must activate the new configuration after creation in order to use it.

Activating a configuration

Only one of your multiple configurations can be active at a given time. The active configuration is the configuration whose properties will govern the behavior of the gcloud CLI.

To activate a new configuration or switch to a new active configuration, run: gcloud config configurations activate:

 

gcloud config configurations activate [NAME]

 

There are also a few useful videos on YouTube about these topics: