Install gsutil

This page describes the installation and setup of gsutil, a tool that enables you to access Cloud Storage from the command-line using HTTPS.

Simply installing gsutil gives you immediate read and/or write access to public data. Authenticating to the Cloud Storage service gives you read and/or write access to protected data that has been shared with you. Enabling billing gives you the ability to create and manage your own buckets.

System requirements

  • The gsutil tool runs on Linux/Unix, Mac OS, and Windows (XP or later).

  • If you plan to use composite objects, you need to install compiled crcmod. On Windows, this is only available for 32-bit Python.

Installing gsutil

The officially supported installation and update method for gsutil is as part of the Google Cloud SDK.

Installing gsutil as part of the Google Cloud SDK

Follow the instructions for your operating system to install gsutil as a part of the Google Cloud SDK:

Linux
  1. Enter the following at a command prompt:
    curl https://sdk.cloud.google.com | bash
  2. When prompted, choose a location on your file system (usually your Home directory) to create the google-cloud-sdk subdirectory under.
  3. If you'd like to add Cloud SDK command-line tools to your PATH and enable command completion, answer y when prompted.
  4. Restart your shell:
    exec -l $SHELL
  5. Run gcloud init to initialize the gcloud environment:
    gcloud init
Debian/Ubuntu

Package contents

Cloud SDK is available in package format for installation on Debian and Ubuntu systems. This package contains the gcloud, gcloud alpha, gcloud beta, gsutil, and bq commands only. It does not include kubectl or the App Engine extensions required to deploy an application using gcloud commands. If you want these components, you must install them separately as described later in this section.

Prerequisites

Before you install Cloud SDK, make sure that your operating system is one of the following:

Installation
  1. Add the Cloud SDK distribution URI as a package source:
    echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
    Make sure you have apt-transport-https installed:
    sudo apt-get install apt-transport-https ca-certificates gnupg

    Troubleshooting Tip: If your distribution does not support the signed-by option run this command instead:

    echo "deb https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list

    Troubleshooting Tip: Make sure you do not have duplicate entries for the cloud-sdk repo.

  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 -

    Troubleshooting Tip: If you are unable to get latest updates due to an expired key, obtain the latest apt-get.gpg key file.

    Troubleshooting Tip: If your distribution's apt-key command does not support the --keyring argument run this command instead:

    curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

  3. Update and install the Cloud SDK:
    sudo apt-get update && sudo apt-get install google-cloud-sdk
    For additional apt-get options, such as disabling prompts or dry runs, refer to the apt-get man pages.

    Docker Tip: If installing the Cloud SDK inside a Docker image, use a single RUN step instead:

    RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg  add - && apt-get update -y && apt-get install google-cloud-sdk -y
          

  4. Optionally, install any of these additional components:
    • google-cloud-sdk-app-engine-python
    • google-cloud-sdk-app-engine-python-extras
    • google-cloud-sdk-app-engine-java
    • google-cloud-sdk-app-engine-go
    • google-cloud-sdk-bigtable-emulator
    • google-cloud-sdk-cbt
    • google-cloud-sdk-cloud-build-local
    • google-cloud-sdk-datalab
    • google-cloud-sdk-datastore-emulator
    • google-cloud-sdk-firestore-emulator
    • google-cloud-sdk-pubsub-emulator
    • kubectl

    For example, the google-cloud-sdk-app-engine-java component can be installed as follows:

    sudo apt-get install google-cloud-sdk-app-engine-java
  5. Run gcloud init to get started:
    gcloud init

Downgrading Cloud SDK versions

If you'd like to revert to a specific version of Cloud SDK, where `VERSION` is of the form `123.0.0`, run: sudo apt-get update && sudo apt-get install google-cloud-sdk=123.0.0-0

macOS
  1. Enter the following at a command prompt:
    curl https://sdk.cloud.google.com | bash
  2. When prompted, choose a location on your file system (usually your Home directory) to create the google-cloud-sdk subdirectory under.
  3. If you'd like to add Cloud SDK command-line tools to your PATH and enable command completion, answer y when prompted.
  4. Restart your shell:
    exec -l $SHELL
  5. Run gcloud init to initialize the gcloud environment:
    gcloud init
Windows
  1. Download the Cloud SDK installer.

    Alternatively, open a PowerShell terminal and run the following PowerShell commands.

    (New-Object Net.WebClient).DownloadFile("https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe", "$env:Temp\GoogleCloudSDKInstaller.exe")
    
    & $env:Temp\GoogleCloudSDKInstaller.exe
          

  2. Launch the installer and follow the prompts. The installer is signed by Google LLC.

    If you'd like to enable screen reader mode, select the Turn on screen reader mode option for a more streamlined screen reader experience. To read more about the Cloud SDK screen reader experience, refer to the Accessibility features guide.

    Google Cloud SDK Setup welcome dialog for Windows with checkbox for enabling screen reader mode

  3. Cloud SDK requires Python. Supported versions are 3.5 to 3.8, and 2.7.9 or higher.

    The installer will install all necessary dependencies, including the needed Python version. While Cloud SDK currently uses Python 3 by default, you can use an existing Python installation if necessary by unchecking the option to 'Install Bundled Python'.

  4. After installation has completed, the installer presents several options:

    Windows installer prompts

    Make sure that the following are selected:

    • Start Google Cloud SDK Shell
    • Run 'gcloud init'

    The installer starts a terminal window and runs the gcloud init command.

  5. The default installation does not include the App Engine extensions required to deploy an application using gcloud commands. These components can be installed using the Cloud SDK component manager.
Troubleshooting tips:
  • If the Cloud SDK fails to run after installing version 274.0.0, please refer to this tracking bug for the latest workarounds.
  • If your installation is unsuccessful due to the find command not being recognized, ensure your `PATH` environment variable is set to include the folder containing `find`. Usually, this is C:\WINDOWS\system32;.
  • If you have just uninstalled Cloud SDK, you will need to reboot your system before installing Cloud SDK again.

Perform updates with the components update command: gcloud components update.

To learn how to use gsutil, see Quickstart: Using the gsutil Tool exercise, or run gsutil help.

Alternative installation methods

There are several ways to install gsutil as a stand-alone product. You may prefer one of these methods if you do not want any of the other components that come with the Cloud SDK, or if you are managing packages with PyPI.

If you are installing gsutil as a standalone, an additional system requirement is that you must have Python installed on your computer. gsutil officially supports minor versions 2.7.x through 3.7.x. Python is installed by default on most distributions of Linux and macOS, but not on Windows; you must install Python before you can run gsutil on Windows.

Expand the desired method for instructions.

Setting Up Credentials to Access Protected Data

Installing gsutil allows you to download and access publicly-accessible objects, but in order to access protected data or write to a protected bucket, you need to set up credentials (authenticate). For example, if someone else has created a Cloud Storage account and uploaded data that is only accessible to you or other specific individuals, you must set up your credentials to the Cloud Storage service to be able to access this data.

If you installed gsutil as part of the Google Cloud SDK, follow these instructions. Otherwise, see the Authenticate stand-alone gsutil section.

Authenticate Google Cloud SDK

When using gsutil as part of the Google Cloud SDK, OAuth2 is used to authenticate and authorize access. Note that you may have already performed the following steps if you performed Installing gsutil as part of the Google Cloud SDK above. If you ran gcloud init previously, you are asked if you want to re-initialize the configuration or create a new one.

  1. Open a command prompt instance.

  2. Run gcloud init at the command prompt.

    You receive the following output:

    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)?
    

  3. Type "Y" and press enter to login.

    • The command prints a URL and tries to open a browser window to request access to your project. If a browser window can be opened, you receive the following output:

      Your browser has been opened to visit:
       
      https://accounts.google.com/o/oauth2/auth?redirect_uri=http%3A%2F%2F...
      

      Go to the next step.

    • If you are working on a local machine and your browser doesn't automatically load the URL, retry the gcloud init command with the --console-only flag:

      gcloud init --console-only
      

      If you use this command, or if the Cloud SDK detects that a browser can not be opened (such as if you are working on a remote machine), you receive the following output:

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

      Open a browser and navigate to the URL provided.

  4. If prompted, sign in with the Google account associated with your Cloud Storage data in the browser window.

  5. Grant access.

    • If the browser window opened automatically, review the application permissions and click Accept when you are ready. The verification code is then automatically sent to the command line tool.

    • If you are working on a remote machine or used the --console-only flag, copy the verification code from the URL and paste it to the terminal command line, after Enter verification code:.

  6. Choose the default project for this configuration.

    After setting up your credentials, the gcloud command-line tool prompts you for a default project for this configuration and provides a list of available projects. Select a project ID from the list.

    When you set this property, gsutil commands that require a project, such as gsutil mb, use the default project ID unless you override them with the -p flag or set the CLOUDSDK_CORE_PROJECT environment variable.

That's it. You're ready to access protected data. To see a listing of gsutil commands, type gsutil at the command prompt.

Authenticate stand-alone gsutil

Authenticate with HMAC

While OAuth 2.0 is the recommended way to authenticate gsutil, you can also use HMAC keys for your credentials. To authenticate with HMAC, use the -a flag in the gsutil config command:

gsutil config -a

Using this command takes you through a similar process as authenticating the stand-alone gsutil (see previous section), except you are prompted for the access ID and secret associated with your HMAC key.

If you are using the Google Cloud SDK, you also should disable credential passing using the command:

gcloud config set pass_credentials_to_gsutil false