How to install gsutil on Centos/ubuntu?

How to Install gsutil on Centos ?

In this article we will explain how to install gsutil on Centos.

Google Cloud storage

Google Cloud Storage is unified object storage for developers and enterprises, from live data serving to data analytics/ML to data archiving.
Let us see how to Upload data to google cloud storage using “gsutil”

1. Install “gsutil”

Type following command in your shell prompt

1 2 3   curl https://sdk.cloud.google.com | bash  

The output of this command 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37   Your current Cloud SDK version is: 149.0.0 Installing components from version: 149.0.0   ++ | These components will be installed. | ++++ | Name | Version | Size | ++++ | BigQuery Command Line Tool | 2.0.24 | < 1 MiB | | BigQuery Command Line Tool (Platform Specific) | 2.0.24 | < 1 MiB | | Cloud SDK Core Libraries (Platform Specific) | 2017.03.24 | < 1 MiB | | Cloud Storage Command Line Tool | 4.23 | 2.8 MiB | | Cloud Storage Command Line Tool (Platform Specific) | 4.23 | < 1 MiB | | Default set of gcloud commands | | | | gclouddeps (Linux, x86_64) | 2017.03.24 | 3.9 MiB |   For the latest full release notes, please visit: https://cloud.google.com/sdk/release_notes   #============================================================# #= Creating update staging area =# #============================================================# #= Installing: BigQuery Command Line Tool =# #============================================================# #= Installing: BigQuery Command Line Tool (Platform Spec… =# #============================================================# #= Installing: Cloud SDK Core Libraries (Platform Specific) =# # ============================================================# #= Installing: Cloud Storage Command Line Tool =# #============================================================# #= Installing: Cloud Storage Command Line Tool (Platform… =# #============================================================# #= Installing: Default set of gcloud commands =# #============================================================#  

 

By default it will be installed inside folder “/root/google-cloud-sdk/bin/”

You can add the folder “/root/google-cloud-sdk/bin/” to your PATH variable to avoid using full path every time.

Simply installing “gsutil” gives you immediate read and/or write access to public data. But if you want to access your own private repos, you need to configure “gsutil” with your own
auth details.

Configuring gsutil

Run the following command to configure “gsutil”

1 2 3   gsutil init consoleonly  

Output would be like below

1 2 3 4 5 6 7   Welcome! This command will take you through the configuration of gcloud.   Your current configuration has been set to: [default]   To continue, you must login. Would you like to login (Y/n)?  

If you press Y , it will show following

1 2 3 4 5 6 7   Go to the following link in your browser:   https://accounts.google.com/o/oauth2/auth?redirect_uri=urn%3Aietf%3Awg%3A…   Enter verification code:  

Copy the URL and paste it in your browser. It will force you to login to your google cloud console. Once you login you will be redirected to a page which has the  “verification code” . Please copy it and enter in the console , where it asked the verification code.

This will complete your configuration. Now you can navigate throgh your repos using gsutil

Few examples are below

List the repos in your project, use “gsutil ls”

1 2 3 4 5 6 7   #gsutil ls gs://test-bucket1/ gs://test-bucket-2/   #  

To upload a file to your repo, use “gsutil cp”

1 2 3   gsutil cp Desktop/myimage.png gs://test-bucket1/  

To delete an object, use “gsutil rm”

1 gsutil rm gs://test-bucket1/myimage.png

To create a new bucket, use “gsutil mb”

1 gsutil mb gs://test-bucket1/

You can find more details at official documentation

SUMMARY

In this article we explained how to install and configure gsutil on Centos/Linux. Please try it out. 

As always, feel free to drop us a note if you have any questions or feedback using our comment form below. Always Happy to help

Author: , 0000-00-00