1. Preparatory work
1.1 Viewing the System Python version
Linux installs Python version 2.7 or later when installing Google SDK
You can use Python-v to view the Python version in the current environment.
If the Python version is less than 2.7, you will need to reinstall Python and set it as the default Python
1.2 Download the Google SDK
CD to the location where you want to save the Google SDK, execute wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/ Google-cloud-sdk-158.0.0-linux-x86_64.tar.gz
1.3 Adding Gcloud to environment variables
For example, the Google SDK download location is:/opt
Add the bottom line of code to the last line in the/etc/profile file
Export path= $PATH:/opt/google-cloud-sdk/bin
Execute source/etc/profile command
Execute which gcloud, if the environment variable is configured successfully, will return the location of Gcloud, as follows
/opt/google-cloud-sdk/bin/gcloud
2. Initializing the SDK
2.1 Execution: Gcloud Init
2.2 Return information: To continue, you must log in. Would you like to log in (y/n)?
2.3 Input: Y
2.4 Next, you will be asked to select the project (or log in first, the landing will not appear this step, remember ...), the specific information is as follows:
Pick Cloud Project to use:
[1] Fir-demo-project
[2] itemall-167201
[3] starlit-fire-167006
[4] Create a new project
Please enter your numeric choice:
2.5 Enter the item number you want to use, and if you have not created a project, you can choose Create a new project
2.6 Next you will be asked to enter the project ID (must be unique and cannot be modified), such as itemall-20170612
2.7 (This step is not required, you need to do this if the not setting default zone/region appears)
Set the default project and execute the following command
Gcloud Config set Project Project ID
Example: Gcloud config set project itemall-20170612
3. Get Google API key
After the default project is configured, key authentication is required.
3.1 Immediately after the previous step, execute the following code
Gcloud Auth Application-default Login
will return the following information
Https://accounts.google.com/o/oauth2/auth?redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&prompt=select_ Account&response_type=code&client_id= 764086051850-6qr4p6gpi6hn506pt8ejuq83di341hur.apps.googleusercontent.com&scope=https%3a%2f% 2fwww.googleapis.com%2fauth%2fuserinfo.email+https%3a%2f%2fwww.googleapis.com%2fauth%2fcloud-platform& Access_type=offline
Enter Verification Code:
Paste the link in the browser, select your current account login, you will see an authentication code such as: 4/bnmwhnh2yvjkpia7xjey2p82airamxcpj7brs15jhke, input can, then generate a JSON file, and return the specific save location information, the file holds the current account of the authentication information
3.2 Configure the save location of the JSON file where the authentication information is stored as an environment variable (must!)
Add the following code to the last line of the/etc/profile file
Export Google_application_credentials=/root/.config/gcloud/application_default_credentials.json
Execute the source/etc/profile command to refresh the configuration file
3.3 Execute Gcloud Auth List command to view certified account information
If [email protected] has been authenticated, the return information is as follows:
Credentialed Accounts:
-[email protected] ACTIVE
To set the active account, run:
$ gcloud Config Set account ' account
Install Google SDK configuration Google API translation environment under Linux