ローカル環境にgcloudをインストール


# 環境
- Ubuntu 22.04LTS

# 手順

apt-transport-httpsをインストール
```bash
$ sudo apt-get install -y apt-transport-https ca-certificates gnupg
```

リストが存在している＆重複がない　ことを確認する

```bash
$ sudo cat /etc/apt/sources.list.d/google-cloud-sdk.list
# ない場合：　cat: /etc/apt/sources.list.d/google-cloud-sdk.list: そのようなファイルやディレクトリはありません
# ある場合：　deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main
```

Cloud SDK の配布 URI をパッケージ ソースとして追加
```bash
$ echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
```

Google Cloud の公開鍵をインポートする
```bash
$ curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
```

Cloud SDKと関連パッケージ をインストールする
```bash
$ sudo apt-get update && sudo apt-get install -y google-cloud-sdk google-cloud-sdk-app-engine-python google-cloud-sdk-pubsub-emulator

# 関連パッケージ一覧はこちら
# google-cloud-sdk-app-engine-python
# google-cloud-sdk-app-engine-python-extras
# google-cloud-sdk-app-engine-java
# google-cloud-sdk-app-engine-go
# google-cloud-sdk-bigtable-emulator
# google-cloud-sdk-cbt
# google-cloud-sdk-cloud-build-local
# google-cloud-sdk-datalab
# google-cloud-sdk-datastore-emulator
# google-cloud-sdk-firestore-emulator
# google-cloud-sdk-pubsub-emulator
# kubectl
```



初期化して開始する
```bash
$ gcloud init

Welcome! This command will take you through the configuration of gcloud.
Your current configuration has been set to: [default]
You can skip diagnostics next time by using the following flag:
  gcloud init --skip-diagnostics
Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.                                                                                                                     
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).
You must log in to continue. Would you like to log in (Y/n)?  
```

Yを入力してEnterを押すと、ブラウザが立ち上がるので、紐づけるgoogleアカウントを選択
さらに、紐づけるプロジェクトを選択する
```bash
Your browser has been opened to visit:

    https://accounts.google.com/o/oauth2/auth?response_type=code&client_id= ～省略～

You are logged in as: [xxxxxxxx@zzzzzzz].

Pick cloud project to use: 
 [1] project-AAA
 [2] project-BBB
 [3] project-CCC
 [4] project-DDD
 [5] project-EEE
 [6] Enter a project ID
 [7] Create a new project

Please enter numeric choice or text value (must exactly match list item):  
```

デフォルトリージョンを設定するか。Yを入力してエンター
```bash
Your current project has been set to: [project-DDD].
Do you want to configure a default Compute Region and Zone? (Y/n)?  
```

めっちゃいっぱいでる。。。
基本的にasia-northeast1-aの34を入力すればOKでしょう。
各リージョンとゾーンでどんなCPUとGPUが使われているかは、[ここから](https://cloud.google.com/compute/docs/regions-zones#available)確認可能です。
```bash
Which Google Compute Engine zone would you like to use as project default?

If you do not specify a zone via a command line flag while working with Compute Engine resources, the default is assumed.
 [1] us-east1-b
 [2] us-east1-c
 [3] us-east1-d
 [4] us-east4-c
 [5] us-east4-b
 [6] us-east4-a
 [7] us-central1-c
 [8] us-central1-a
 [9] us-central1-f
 [10] us-central1-b
 [11] us-west1-b
 [12] us-west1-c
 [13] us-west1-a
 [14] europe-west4-a
 [15] europe-west4-b
 [16] europe-west4-c
 [17] europe-west1-b
 [18] europe-west1-d
 [19] europe-west1-c
 [20] europe-west3-c
 [21] europe-west3-a
 [22] europe-west3-b
 [23] europe-west2-c
 [24] europe-west2-b
 [25] europe-west2-a
 [26] asia-east1-b
 [27] asia-east1-a
 [28] asia-east1-c
 [29] asia-southeast1-b
 [30] asia-southeast1-a
 [31] asia-southeast1-c
 [32] asia-northeast1-b
 [33] asia-northeast1-c
 [34] asia-northeast1-a
 [35] asia-south1-c
 [36] asia-south1-b
 [37] asia-south1-a
 [38] australia-southeast1-b
 [39] australia-southeast1-c
 [40] australia-southeast1-a
 [41] southamerica-east1-b
 [42] southamerica-east1-c
 [43] southamerica-east1-a
 [44] asia-east2-a
 [45] asia-east2-b
 [46] asia-east2-c
 [47] asia-northeast2-a
 [48] asia-northeast2-b
 [49] asia-northeast2-c
 [50] asia-northeast3-a

Did not print [54] options.
Too many options [104]. Enter "list" at prompt to print choices fully.
Please enter numeric choice or text value (must exactly match list item):  
```

そうすると、リージョンとゾーンがセットされて完了する。
```bash
Your project default Compute Engine zone has been set to [asia-northeast1-a].
You can change it by running [gcloud config set compute/zone NAME].
Your project default Compute Engine region has been set to [asia-northeast1].
You can change it by running [gcloud config set compute/region NAME].
Created a default .boto configuration file at [/home/user01/.boto]. See this file and
[https://cloud.google.com/storage/docs/gsutil/commands/config] for more
information about configuring Google Cloud Storage.
Your Google Cloud SDK is configured and ready to use!

* Commands that require authentication will use メールアドレス by default
* Commands will reference project `プロジェクト名` by default
* Compute Engine commands will use region `asia-northeast1` by default
* Compute Engine commands will use zone `asia-northeast1-a` by default

Run `gcloud help config` to learn how to change individual settings

This gcloud configuration is called [default]. You can create additional configurations if you work with multiple accounts and/or projects.

Run `gcloud topic configurations` to learn more.

Some things to try next:
* Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command.

* Run `gcloud topic --help` to learn about advanced features of the SDK like arg files and output formatting

* Run `gcloud cheat-sheet` to see a roster of go-to `gcloud` commands.
```

# 参考
[Cloud SDK のインストール](https://cloud.google.com/sdk/docs/install?hl=ja)