Skip to content

Setting Up gsutil Command-Line Tool on Ubuntu

Steps
5
Covers
Ubuntu
Versions & support
About Ubuntu →
On this page 5 steps

In the world of cloud computing, managing Google Cloud Storage (GCS) effectively is crucial for developers and system administrators. The gsutil command-line tool is a powerful utility that facilitates the interaction with GCS and other Google Cloud services. In this article, we’ll walk through the steps of installing and configuring gsutil on Linux systems, ensuring you have a smooth and efficient experience managing your cloud resources.

Introduction

gsutil is part of the Google Cloud SDK, a set of tools that enable you to manage resources and applications hosted on Google Cloud. This utility not only helps in performing day-to-day tasks like uploading, downloading, and deleting objects in cloud storage but also supports batch operations, scripting, and automation.

Prerequisites

  • A Linux operating system
  • Access to a terminal
  • Basic knowledge of Linux commands
  • An active Google Cloud account

Step 1 of 5Installing Google Cloud SDK

The first step in using gsutil is to install the Google Cloud SDK, which includes gsutil.

  1. Add the Cloud SDK distribution URI as a package source:
    echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list 
    
  2. Import the Google Cloud public key:
    curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - 
    
    Update and install the Cloud SDK:

    sudo apt-get update && sudo apt-get install google-cloud-sdk 
    

Step 2 of 5Initial Configuration of Google Cloud SDK

After installation, run the initial configuration:

gcloud init 

This command guides you through:

  1. Logging into your Google account.
  2. Setting up a GCP project.
  3. Setting a default region and zone.

Step 3 of 5Authenticating gsutil

To use gsutil, you need to authenticate it with your Google Cloud account. This can be done as part of the gcloud init process or separately by:

gcloud auth login 

Step 4 of 5Testing gsutil

To confirm that gsutil is installed and configured correctly, try listing your GCS buckets:

gsutil ls 

This command should return a list of your GCS buckets, if any.

Step 5 of 5Learning Basic gsutil Commands

Here are some fundamental gsutil commands:

  1. Create a new bucket:
    gsutil mb gs://[BUCKET_NAME] 
    
  2. Upload a file to a bucket:
    gsutil cp [FILE_NAME] gs://[BUCKET_NAME] 
    
  3. List contents of a bucket:
    gsutil ls gs://[BUCKET_NAME] 
    

Conclusion

By efficiently installing and configuring gsutil on your Linux system, you are now equipped to manage Google Cloud Storage with ease. This powerful tool not only enhances your ability to interact with GCS but also opens up possibilities for automating and scripting various cloud-related tasks.

Remember, gsutil is a versatile utility with numerous commands and options. For more advanced uses, refer to the official Google Cloud documentation and explore the comprehensive set of features that gsutil offers.

Additional Resources
Google Cloud SDK Documentation: For a deeper dive into the capabilities of the Cloud SDK.
gsutil Command Reference: To explore more gsutil commands and options.
Automating Tasks: Look into scripting with gsutil for automation and batch operations.
With gsutil installed on your Linux system, you’re well on your way to proficiently managing your cloud resources, improving your workflows, and leveraging the power of Google Cloud.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top