Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Google Cloud Shell Tutorial

Introduction to Google Cloud Shell

Google Cloud Shell is an online development and operations environment accessible anywhere with your browser. It provides you with command-line access to your cloud resources directly from the Google Cloud Console. It comes pre-loaded with development tools including the Google Cloud SDK, so you can manage your projects and resources without having to install anything on your local machine.

Getting Started with Cloud Shell

To start using Google Cloud Shell, follow these steps:

  1. Open the Google Cloud Console.
  2. Click on the Activate Cloud Shell icon in the top-right corner of the console.
  3. A Cloud Shell session opens inside a new frame at the bottom of the Google Cloud Console and displays a command-line prompt.

Basic Cloud Shell Commands

Here are some basic commands that you can use in Cloud Shell:

$ gcloud version

This command displays the version of the Google Cloud SDK installed in Cloud Shell.

Google Cloud SDK 322.0.0
bq 2.0.60
core 2021.01.30
gsutil 4.58
$ gcloud projects list

This command lists all the projects associated with your Google Cloud account.

PROJECT_ID NAME PROJECT_NUMBER
example-project-123 Example Project 123456789012
$ gcloud config set project [PROJECT_ID]

Replace [PROJECT_ID] with your project ID to set the default project for your gcloud commands.

Updated property [core/project] to [example-project-123].

Using Cloud Shell for Development

Cloud Shell provides a full development environment, including a code editor, to help you write, edit, and run your code directly from the browser.

  1. Open the Editor by clicking the Open Editor icon in the top-right corner of the Cloud Shell window.
  2. The editor will open a new tab with a full-featured code editor.
  3. You can create, edit, and save files as you would in any other code editor.

Managing Resources with Cloud Shell

Cloud Shell can be used to manage various Google Cloud resources such as Compute Engine instances, Cloud Storage, and more. Here are a few examples:

$ gcloud compute instances list

This command lists all the Compute Engine instances in your project.

NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
instance-1 us-central1-a n1-standard-1 10.128.0.2 34.68.194.64 RUNNING
$ gsutil ls

This command lists all the Cloud Storage buckets in your project.

gs://example-bucket/

Customizing Your Cloud Shell Environment

You can customize your Cloud Shell environment by installing additional tools and configuring settings. Any changes you make will persist across sessions.

$ sudo apt-get install [PACKAGE_NAME]

Replace [PACKAGE_NAME] with the name of the package you want to install.

Troubleshooting and Tips

Here are some tips and common troubleshooting steps for using Cloud Shell:

  • If Cloud Shell is slow or unresponsive, try restarting the session by clicking the Restart icon.
  • Use Ctrl+C to terminate a running command if it becomes unresponsive.
  • Check the Google Cloud Shell documentation for more detailed information and advanced usage.