Setting Up a Cloud Development Environment with Google Cloud SDK
Google Cloud SDK (formerly gcutil) is a command-line toolset for Google Cloud Platform (GCP), used to manage virtual machine instances (Compute Engine), App Engine applications, and other cloud services. This guide explains how to install and configure the Cloud SDK on Windows using Cygwin to get started quickly with GCP.
Environment Preparation: Installing Cygwin
Since Google Cloud SDK relies on a Unix-like environment, Windows users need to install Cygwin first to provide a Linux terminal emulation.
- Visit the Cygwin website to download the installer (choose the 32-bit version). The official documentation notes known issues with Python in 64-bit Cygwin that may cause Cloud SDK to malfunction.
- Run the installer. When selecting a mirror, users in certain regions can use
http://mirrors.163.com/cygwin/to speed up downloads. - In the package selection screen, search for and install these required packages:
- python (version 2.7 or 2.6)
- openssl
- curl
- wget
- unzip
When prompted for versions, keep the default or select the latest stable release.
- After installation, a 'Cygwin Terminal' shortcut should appear on the desktop. If not, create one manually: navigate to
binmintty.exein your Cygwin installation directory, create a shortcut, and modify its target to:D:cygwinbinmintty.exe -i /Cygwin-Terminal.ico -(adjust the path according to your actual installation).
Installing Google Cloud SDK
Open the Cygwin terminal and follow these steps.
1. Download and Extract the SDK
wget https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.zip
unzip google-cloud-sdk.zip
2. Run the Installation Script
curl https://dl.google.com/dl/cloudsdk/release/install_google_cloud_sdk.bash | bash
The script will prompt for:
- Extraction Directory: Press Enter to accept the default, which creates a
google-cloud-sdkfolder in your home directory. - Usage Reporting: Choose whether to participate in the user experience improvement program (Y/n).
- Language Runtime Selection: Select App Engine language support based on your needs:
[1] Java [2] Python and PHP [3] Go [4] No App Engine (you can install App Engine tools later)Choose
4if you only need to manage Compute Engine (VPS). Choose2for Python/PHP application development. - Update Configuration Files: Press Enter when prompted to update
.bashrc. When asked to modify$PATHand enable bash completion, enterYand press Enter.
3. Restart Terminal and Initialize
Close and reopen the Cygwin window for changes to take effect. Then initialize the SDK:
gcloud init
Account Authentication and Connecting to Compute Engine Instances
1. Log in to Your Google Account
gcloud auth login
After execution, the terminal will display an authorization link. Copy it to your browser, log in with your Google account, grant permission, and paste the returned verification code back into the terminal to complete authentication.
2. Connect to a Virtual Machine Instance
After creating a Compute Engine instance in the Google Cloud Console, click the SSH button to see a connection command similar to:
gcloud compute ssh --zone="your-zone" "instance-name" --project="your-project-id"
Copy and run this command in the Cygwin terminal to establish an SSH connection. Once connected, to gain root privileges, run:
sudo su
Note: It is not recommended to directly change the root password, as this may affect the native SSH connection functionality of the Google Cloud Console.
Common Issues and Notes
- Version Updates: Cloud SDK is updated regularly. Run
gcloud components updateperiodically to get the latest features and fixes. - Network Issues: Users experiencing slow downloads may need to configure a proxy or use a reliable network connection.
- Python Version: Cloud SDK is still compatible with Python 2.7, but Google recommends migrating to Python 3. If using a Python 3 environment, ensure the corresponding version is installed in Cygwin.
Following these steps, you can quickly set up a Google Cloud command-line management environment on Windows to conveniently operate virtual machine instances and deploy applications.