Google Compute Engine を使うための準備（Google Cloud SDK インストール - Linux &amp;amp; OS X 編）

この記事は以下の一部です。

googlecomputeengine - Google Compute Engine 入門 - Qiita
http://qiita.com/yuko/items/460ac35d8706e8df1290

![cloud-sdk-logo_short_900px.jpg](https://qiita-image-store.s3.amazonaws.com/0/40971/d0dd3cf2-61af-571c-22a1-148d1a0ba456.jpeg "cloud-sdk-logo_short_900px.jpg")

Google Cloud SDK — Google Developers
https://developers.google.com/cloud/sdk/

>System Requirements: Google Cloud SDK runs on Windows, Mac OS X and Linux, and requires Python 2.7.x. Some of the individual tools bundled with Cloud SDK have more stringent requirements: using App Engine tools for Java development requires Java 1.7+, and using SSH functionality from gcutil tool on Windows requires a 32-bit Cygwin installation.

##システム要件（LinuxとOS X）

- Python 2.7.x
- Java 1.7+ (GAE/Jをしたい人。Google Compute Engine を試すためだけなら不要)

##インストール

###1. Python

`$ python --version` で Python のバージョンを確認してみてください。

- Ubuntu 12.04 : デフォルトで2.7.3 が入っていたのでそのまま使えます
- CentOS 6.4 : 2.6.x 系が入っているので、アップデートが必要

CentOS6にpython2.7を入れる | ちいさな創々 http://www.petitec.com/2013/04/centos6%E3%81%ABpython2-7%E3%82%92%E5%85%A5%E3%82%8C%E3%82%8B/

- OS X Moutain Lion : デフォルトで 2.7.2 が入っていたのでそのまま使えます。Homebrew で `brew install python` をしても良いです。（もちろん macports でも！）

###2. Google Cloud SDK

SDKのインストールは下記一行だけ！

``` bash
$ curl https://sdk.cloud.google.com | bash
```

実行例

``` bash
$ curl https://sdk.cloud.google.com | bash

Directory to extract under (this will create a directory google-cloud-sdk) (/Users/test): 
tar -C "/Users/test" -xvf "/var/folders/fc/xsv52lk948919ll0yqx5958m0000gp/T/tmp.XXXXXXXXXX.i5xRW0Vz/google-cloud-sdk.tar.gz"
x google-cloud-sdk/
x google-cloud-sdk/lib/
x google-cloud-sdk/lib/apitools/
x google-cloud-sdk/lib/apitools/base/
x google-cloud-sdk/lib/apitools/base/py/
x google-cloud-sdk/lib/apitools/base/py/util.py
x google-cloud-sdk/lib/apitools/base/py/transfer.py
x google-cloud-sdk/lib/apitools/base/py/http_wrapper.py
x google-cloud-sdk/lib/apitools/base/py/extra_types.py
x google-cloud-sdk/lib/apitools/base/py/exceptions.py
x google-cloud-sdk/lib/apitools/base/py/encoding.py
x google-cloud-sdk/lib/apitools/base/py/credentials_lib.py
x google-cloud-sdk/lib/apitools/base/py/batch.py
x google-cloud-sdk/lib/apitools/base/py/base_cli.py
x google-cloud-sdk/lib/apitools/base/py/base_api.py
x google-cloud-sdk/lib/apitools/base/py/app2.py
x google-cloud-sdk/lib/apitools/base/py/__init__.py
x google-cloud-sdk/lib/apitools/base/__init__.py
x google-cloud-sdk/lib/apitools/__init__.py
x google-cloud-sdk/lib/yaml/
x google-cloud-sdk/lib/yaml/tokens.py
x google-cloud-sdk/lib/yaml/serializer.py
x google-cloud-sdk/lib/yaml/scanner.py
x google-cloud-sdk/lib/yaml/resolver.py
x google-cloud-sdk/lib/yaml/representer.py
x google-cloud-sdk/lib/yaml/reader.py
x google-cloud-sdk/lib/yaml/parser.py
x google-cloud-sdk/lib/yaml/nodes.py
x google-cloud-sdk/lib/yaml/loader.py
x google-cloud-sdk/lib/yaml/events.py
x google-cloud-sdk/lib/yaml/error.py
x google-cloud-sdk/lib/yaml/emitter.py
x google-cloud-sdk/lib/yaml/dumper.py
x google-cloud-sdk/lib/yaml/cyaml.py
x google-cloud-sdk/lib/yaml/constructor.py
x google-cloud-sdk/lib/yaml/composer.py
x google-cloud-sdk/lib/yaml/__init__.py
x google-cloud-sdk/lib/uritemplate/
x google-cloud-sdk/lib/uritemplate/uritemplate.py
x google-cloud-sdk/lib/uritemplate/__init__.py
x google-cloud-sdk/lib/socks/
x google-cloud-sdk/lib/socks/__init__.py
x google-cloud-sdk/lib/protorpc/
x google-cloud-sdk/lib/protorpc/wsgi/
x google-cloud-sdk/lib/protorpc/wsgi/util.py
x google-cloud-sdk/lib/protorpc/wsgi/service.py
x google-cloud-sdk/lib/protorpc/wsgi/__init__.py
x google-cloud-sdk/lib/protorpc/webapp/
x google-cloud-sdk/lib/protorpc/webapp/google_imports.py
x google-cloud-sdk/lib/protorpc/webapp/forms.py
x google-cloud-sdk/lib/protorpc/webapp/service_handlers.py
x google-cloud-sdk/lib/protorpc/webapp/__init__.py
x google-cloud-sdk/lib/protorpc/util.py
x google-cloud-sdk/lib/protorpc/transport.py
x google-cloud-sdk/lib/protorpc/remote.py
x google-cloud-sdk/lib/protorpc/registry.py
x google-cloud-sdk/lib/protorpc/protourlencode.py
x google-cloud-sdk/lib/protorpc/protojson.py
x google-cloud-sdk/lib/protorpc/protobuf.py
x google-cloud-sdk/lib/protorpc/non_sdk_imports.py
x google-cloud-sdk/lib/protorpc/messages.py
x google-cloud-sdk/lib/protorpc/message_types.py
x google-cloud-sdk/lib/protorpc/google_imports.py
x google-cloud-sdk/lib/protorpc/generate_python.py
x google-cloud-sdk/lib/protorpc/generate_proto.py
x google-cloud-sdk/lib/protorpc/generate.py
x google-cloud-sdk/lib/protorpc/definition.py
x google-cloud-sdk/lib/protorpc/descriptor.py
x google-cloud-sdk/lib/protorpc/__init__.py
x google-cloud-sdk/lib/oauth2client/
x google-cloud-sdk/lib/oauth2client/xsrfutil.py
x google-cloud-sdk/lib/oauth2client/util.py
x google-cloud-sdk/lib/oauth2client/tools.py
x google-cloud-sdk/lib/oauth2client/old_run.py
x google-cloud-sdk/lib/oauth2client/multistore_file.py
x google-cloud-sdk/lib/oauth2client/locked_file.py
x google-cloud-sdk/lib/oauth2client/keyring_storage.py
x google-cloud-sdk/lib/oauth2client/gce.py
x google-cloud-sdk/lib/oauth2client/file.py
x google-cloud-sdk/lib/oauth2client/django_orm.py
x google-cloud-sdk/lib/oauth2client/crypt.py
x google-cloud-sdk/lib/oauth2client/clientsecrets.py
x google-cloud-sdk/lib/oauth2client/client.py
x google-cloud-sdk/lib/oauth2client/appengine.py
x google-cloud-sdk/lib/oauth2client/anyjson.py
x google-cloud-sdk/lib/oauth2client/__init__.py
x google-cloud-sdk/lib/oauth2/
x google-cloud-sdk/lib/oauth2/__init__.py
x google-cloud-sdk/lib/mimeparse/
x google-cloud-sdk/lib/mimeparse/__init__.py
x google-cloud-sdk/lib/httplib2/
x google-cloud-sdk/lib/httplib2/iri2uri.py
x google-cloud-sdk/lib/httplib2/cacerts.txt
x google-cloud-sdk/lib/httplib2/__init__.py
x google-cloud-sdk/lib/httplib2/LICENSE
x google-cloud-sdk/lib/argcomplete/
x google-cloud-sdk/lib/argcomplete/scripts/
x google-cloud-sdk/lib/argcomplete/scripts/register-python-argcomplete
x google-cloud-sdk/lib/argcomplete/scripts/python-argcomplete-check-easy-install-script
x google-cloud-sdk/lib/argcomplete/scripts/activate-global-python-argcomplete
x google-cloud-sdk/lib/argcomplete/my_shlex.py
x google-cloud-sdk/lib/argcomplete/my_argparse.py
x google-cloud-sdk/lib/argcomplete/completers.py
x google-cloud-sdk/lib/argcomplete/__init__.py
x google-cloud-sdk/lib/apiclient/
x google-cloud-sdk/lib/apiclient/__init__.py
x google-cloud-sdk/lib/apiclient/schema.py
x google-cloud-sdk/lib/apiclient/push.py
x google-cloud-sdk/lib/apiclient/oauth.py
x google-cloud-sdk/lib/apiclient/model.py
x google-cloud-sdk/lib/apiclient/mimeparse.py
x google-cloud-sdk/lib/apiclient/http.py
x google-cloud-sdk/lib/apiclient/errors.py
x google-cloud-sdk/lib/apiclient/discovery.py
x google-cloud-sdk/lib/apiclient/channel.py
x google-cloud-sdk/lib/gflags/
x google-cloud-sdk/lib/gflags/setup.py
x google-cloud-sdk/lib/gflags/setup.cfg
x google-cloud-sdk/lib/gflags/gflags_validators.py
x google-cloud-sdk/lib/gflags/gflags2man.py
x google-cloud-sdk/lib/gflags/__init__.py
x google-cloud-sdk/lib/gflags/README
x google-cloud-sdk/lib/gflags/PKG-INFO
x google-cloud-sdk/lib/gflags/NEWS
x google-cloud-sdk/lib/gflags/Makefile
x google-cloud-sdk/lib/gflags/MANIFEST.in
x google-cloud-sdk/lib/gflags/LICENSE
x google-cloud-sdk/lib/gflags/ChangeLog
x google-cloud-sdk/lib/gflags/COPYING
x google-cloud-sdk/lib/gflags/AUTHORS
x google-cloud-sdk/lib/argparse/
x google-cloud-sdk/lib/argparse/__init__.py
x google-cloud-sdk/lib/argparse/README.txt
x google-cloud-sdk/lib/argparse/NEWS.txt
x google-cloud-sdk/lib/argparse/LICENSE.txt
x google-cloud-sdk/lib/google/
x google-cloud-sdk/lib/google/cloud/
x google-cloud-sdk/lib/google/cloud/sdk/
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/root/
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/root/version.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/root/interactive.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/root/init.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/root/__init__.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/config/
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/config/unset.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/config/set.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/config/list.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/config/__init__.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/components/
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/components/update.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/components/restore.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/components/remove.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/components/list.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/components/__init__.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/auth/
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/auth/revoke.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/auth/print-access-token.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/auth/login.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/auth/list.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/auth/git_helper.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/auth/activate_refresh_token.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/auth/__init__.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/sdktools/__init__.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/gcloud.yaml
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/gcloud.py
x google-cloud-sdk/lib/google/cloud/sdk/gcloud/__init__.py
x google-cloud-sdk/lib/google/cloud/sdk/calliope/
x google-cloud-sdk/lib/google/cloud/sdk/calliope/usage_text.py
x google-cloud-sdk/lib/google/cloud/sdk/calliope/tokenizer.py
x google-cloud-sdk/lib/google/cloud/sdk/calliope/exceptions.py
x google-cloud-sdk/lib/google/cloud/sdk/calliope/base.py
x google-cloud-sdk/lib/google/cloud/sdk/calliope/arg_parsers.py
x google-cloud-sdk/lib/google/cloud/sdk/calliope/actions.py
x google-cloud-sdk/lib/google/cloud/sdk/calliope/__init__.py
x google-cloud-sdk/lib/google/cloud/sdk/core/
x google-cloud-sdk/lib/google/cloud/sdk/core/util/
x google-cloud-sdk/lib/google/cloud/sdk/core/util/platforms.py
x google-cloud-sdk/lib/google/cloud/sdk/core/util/files.py
x google-cloud-sdk/lib/google/cloud/sdk/core/util/edit.py
x google-cloud-sdk/lib/google/cloud/sdk/core/util/console_io.py
x google-cloud-sdk/lib/google/cloud/sdk/core/util/__init__.py
x google-cloud-sdk/lib/google/cloud/sdk/core/updater/
x google-cloud-sdk/lib/google/cloud/sdk/core/updater/update_manager.py
x google-cloud-sdk/lib/google/cloud/sdk/core/updater/snapshots.py
x google-cloud-sdk/lib/google/cloud/sdk/core/updater/schemas.py
x google-cloud-sdk/lib/google/cloud/sdk/core/updater/local_state.py
x google-cloud-sdk/lib/google/cloud/sdk/core/updater/installers.py
x google-cloud-sdk/lib/google/cloud/sdk/core/updater/__init__.py
x google-cloud-sdk/lib/google/cloud/sdk/core/credentials/
x google-cloud-sdk/lib/google/cloud/sdk/core/credentials/gce.py
x google-cloud-sdk/lib/google/cloud/sdk/core/credentials/store.py
x google-cloud-sdk/lib/google/cloud/sdk/core/credentials/legacy.py
x google-cloud-sdk/lib/google/cloud/sdk/core/credentials/gitp2d.py
x google-cloud-sdk/lib/google/cloud/sdk/core/credentials/flow.py
x google-cloud-sdk/lib/google/cloud/sdk/core/credentials/__init__.py
x google-cloud-sdk/lib/google/cloud/sdk/core/credentials/oauth2_landing.html
x google-cloud-sdk/lib/google/cloud/sdk/core/config.json
x google-cloud-sdk/lib/google/cloud/sdk/core/workspaces.py
x google-cloud-sdk/lib/google/cloud/sdk/core/properties.py
x google-cloud-sdk/lib/google/cloud/sdk/core/metrics.py
x google-cloud-sdk/lib/google/cloud/sdk/core/log.py
x google-cloud-sdk/lib/google/cloud/sdk/core/config.py
x google-cloud-sdk/lib/google/cloud/sdk/core/cli.py
x google-cloud-sdk/lib/google/cloud/sdk/core/__init__.py
x google-cloud-sdk/lib/google/cloud/sdk/__init__.py
x google-cloud-sdk/lib/google/cloud/__init__.py
x google-cloud-sdk/lib/google/apputils/
x google-cloud-sdk/lib/google/apputils/stopwatch.py
x google-cloud-sdk/lib/google/apputils/shellutil.py
x google-cloud-sdk/lib/google/apputils/setup_command.py
x google-cloud-sdk/lib/google/apputils/run_script_module.py
x google-cloud-sdk/lib/google/apputils/resources.py
x google-cloud-sdk/lib/google/apputils/file_util.py
x google-cloud-sdk/lib/google/apputils/debug.py
x google-cloud-sdk/lib/google/apputils/datelib.py
x google-cloud-sdk/lib/google/apputils/basetest.py
x google-cloud-sdk/lib/google/apputils/appcommands.py
x google-cloud-sdk/lib/google/apputils/app.py
x google-cloud-sdk/lib/google/apputils/__init__.py
x google-cloud-sdk/lib/google/__init__.py
x google-cloud-sdk/README
x google-cloud-sdk/LICENSE
x google-cloud-sdk/RELEASE_NOTES
x google-cloud-sdk/bin/
x google-cloud-sdk/bin/bootstrapping/
x google-cloud-sdk/bin/bootstrapping/.install_configurations
x google-cloud-sdk/bin/bootstrapping/.default_components
x google-cloud-sdk/bin/bootstrapping/setup.py
x google-cloud-sdk/bin/bootstrapping/print_env_info.py
x google-cloud-sdk/bin/bootstrapping/prerun.py
x google-cloud-sdk/bin/bootstrapping/install.py
x google-cloud-sdk/bin/bootstrapping/bootstrapping.py
x google-cloud-sdk/bin/bootstrapping/__init__.py
x google-cloud-sdk/install.sh
x google-cloud-sdk/install.bat
x google-cloud-sdk/completion.bash.inc
x google-cloud-sdk/completion.zsh.inc
x google-cloud-sdk/path.bash.inc
x google-cloud-sdk/.install/
x google-cloud-sdk/.install/core.snapshot.json
x google-cloud-sdk/.install/core.manifest
x google-cloud-sdk/.install/.download/

"/Users/test/google-cloud-sdk/install.sh"
Welcome to the Google Cloud SDK!

The Google Cloud SDK is currently in developer preview. To help improve the
quality of this product, we collect anonymized data on how the SDK is used.
You may choose to opt out of this collection now (by choosing 'N' at the below
prompt), or at any time in the future by running the following command:
    gcloud config --global-only set disable_usage_reporting true

Do you want to help improve the Google Cloud SDK (Y/n)?  Y <-- Google Cloud SDKの改善に協力してくれますか？（Googleにレポートが送られます。協力してもよい人はYを。レポート送られるのはNGな場合はnを。）


This will install all the core command line tools necessary for working with
the Google Cloud Platform.

If you are developing an App Engine application, please select the 
language your application is written in.  This will install the 
required tools and runtimes for working in that language.  If 
necessary, you can add and remove languages later through the gcloud 
component manager.
  [1]  Java
  [2]  Python and PHP
  [3]  Go
  [4]  No App Engine (you can install App Engine tools later)
Please enter your numeric choice (4):  <-- 今回はCompute Engineのみなので4を選択します。


The following components will be installed:
    ------------------------------------------------------------------------------
    | Big Query Command Line Tool                          |     2.0.18 | < 1 MB |
    | Big Query Command Line Tool (Platform Specific)      |     2.0.18 | < 1 MB |
    | Cloud SDK Core Command Line Tools                    |          1 |        |
    | Cloud SDK Core Libraries (Platform Specific)         | 2014.03.24 | < 1 MB |
    | Cloud SQL Admin Command Line Interface               | 2014.03.18 | < 1 MB |
    | Cloud Storage Command Line Tool                      |       3.42 | 1.8 MB |
    | Cloud Storage Command Line Tool (Platform Specific)  |       3.42 | < 1 MB |
    | Compute Engine Command Line Tool                     |     1.15.0 | < 1 MB |
    | Compute Engine Command Line Tool (Platform Specific) |     1.13.0 | < 1 MB |
    ------------------------------------------------------------------------------

Creating update staging area...


Installing: Big Query Command Line Tool ... Done
Installing: Big Query Command Line Tool (Platform Specific) ... Done
Installing: Cloud SDK Core Command Line Tools ... Done
Installing: Cloud SDK Core Libraries (Platform Specific) ... Done
Installing: Cloud SQL Admin Command Line Interface ... Done
Installing: Cloud Storage Command Line Tool ... Done
Installing: Cloud Storage Command Line Tool (Platform Specific) ... Done
Installing: Compute Engine Command Line Tool ... Done
Installing: Compute Engine Command Line Tool (Platform Specific) ... Done

Creating backup and activating new installation...

Done!

The Google Cloud SDK installer will now prompt you to update an rc 
file to bring
the Google Cloud CLIs into your environment.

Enter path to an rc file to update, or leave blank to use 
[/Users/test/.bash_profile]:  <-- パスの変更のための設定ファイルを聞かれます。そのままEnterで。

Modify profile to update your $PATH? (Y/n)?  Y <-- パスを変更しますか？とのことなのでYを選択。（他のバージョンと共存させるためにPATH変更を行いたくない場合はnにして下さい。）


Modify profile to enable bash completion? (Y/n)?  Y <-- 補完を有効にしますか？とのことなのでYを選択

[/Users/test/.bash_profile] has been updated. Start a new shell for the changes to take effect.

For more information on how to get started, please visit:
  https://developers.google.com/cloud/sdk/gettingstarted


```

上記を実行したユーザーの .bash_profile の一番最後に `~/google-cloud-sdk` の配下をPATHに追加してくれるので、既にインストールされている人も、このインストールで入れた内容が優先されます。

設定を再度読み込むには、新しいターミナルを立ち上げるか以下のコマンドを実行して下さい。

``` bash
source ~/.bashrc

```

####Google Cloud SDK の内容確認

``` bash
$ gcloud components list
```

このコマンドが実行できれば上手くインストールできています。
出力結果はこんな感じです。

``` bash
The following are the components available through the Google Cloud
SDK.  You may choose to install one or more of the pre-configured
packages (which contain everything you need to get started), and/or
any of the individual components below.

-------------------------------------------------------------------------------
|                                  Packages                                   |
|-----------------------------------------------------------------------------|
| Status        | Name                                    | ID         | Size |
|---------------+-----------------------------------------+------------+------|
| Not Installed | Cloud SDK for Go Developers             | pkg-go     |      |
| Not Installed | Cloud SDK for Java Developers           | pkg-java   |      |
| Installed     | Cloud SDK Core Command Line Tools       | pkg-core   |      |
| Not Installed | Cloud SDK for Python and PHP Developers | pkg-python |      |
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------------------------
|                                     Individual Components                                     |
|-----------------------------------------------------------------------------------------------|
| Status        | Name                                     | ID                      |     Size |
|---------------+------------------------------------------+-------------------------+----------|
| Not Installed | App Engine SDK for Go (Mac OS X, x86_64) | gae-go-darwin-x86_64    |  30.1 MB |
| Not Installed | App Engine SDK for Java                  | gae-java                | 146.5 MB |
| Not Installed | App Engine Launcher Application for Mac  | gae-python-launcher-mac |   7.4 MB |
| Not Installed | App Engine SDK for Python and PHP        | gae-python              |  35.9 MB |
| Installed     | Big Query Command Line Tool              | bq                      |   < 1 MB |
| Not Installed | Cloud DNS Admin Command Line Interface   | dns                     |   < 1 MB |
| Installed     | Cloud SDK Core Libraries                 | core                    |   < 1 MB |
| Installed     | Cloud SQL Admin Command Line Interface   | sql                     |   < 1 MB |
| Installed     | Cloud Storage Command Line Tool          | gsutil                  |   1.8 MB |
| Not Installed | Commands That Are In Developer Preview   | preview                 |   < 1 MB |
| Installed     | Compute Engine Command Line Tool         | gcutil                  |   < 1 MB |
-------------------------------------------------------------------------------------------------

To install new components or update existing ones, run:
 $ gcloud components update [component ids]
```