26

I recently started using Google Cloud Storage. Initially I created a dummy project while installing the Cloud SDK. Now I am working on another project. The gsutil is still pointing to my previous project. How do I make it point to my new project??

P.S. I know there is an option of using -p argument, but this does not work on all commands.

user3571631
  • 533
  • 1
  • 6
  • 18
  • You can also look at some of the solutions to a similar question here https://stackoverflow.com/q/46770900/311525 – Scott Jul 27 '18 at 18:48

5 Answers5

72

To change the default project that gcloud (and gsutil) use in a gcloud installation, you should do this:

gcloud config set project desired-project-id-here

You can view your current settings with gcloud config list.

You can view all configurations available with gcloud config configurations list.

You can then switch to an alternate configuration with gcloud config configurations activate [NAME]

Travis Hobrla
  • 4,555
  • 19
  • 19
  • 1
    Is it `desired-project-name-here` or `desired-project-id`? When I tried with name, It returned error and suggested using this command: `gcloud config set project PROJECT_ID` – Venkata Gogu Jul 27 '18 at 15:39
5

I got this fixed by running "gcloud init" and following the commands to reinitialize the configuration.

user3571631
  • 533
  • 1
  • 6
  • 18
1

There are two ways to do this.

First, you could repeat the gsutil setup. Just run gsutil config.

Alternatively, if you don't want to run through setup again, gsutil's config lives in a file called .boto. In Linux, it'll be in your home directory. It's a readable config file. Open it up, scroll down to the line default_project_id =, and change the project after the equals sign.

Edit: I missed that you were using gsutil as part of the gcloud suite. My suggestion only applies if you've installed gsutil directly. Travis's suggestion is the right one if you have gcloud installed.

Brandon Yarbrough
  • 33,119
  • 22
  • 98
  • 134
0

As an alternative to setting a default project in gcloud using gcloud config set project $GCP_PROJECT_NAME

gsutil, just like gcloud, respects the environment variable CLOUDSDK_CORE_PROJECT

you can use export CLOUDSDK_CORE_PROJECT=$GCP_PROJECT_NAME and use gsutil in the new project

StanleyZheng
  • 3,290
  • 2
  • 19
  • 23
0

For scripting, it's safer to set the project just for one gsutil call:

CLOUDSDK_CORE_PROJECT=your-project-id gsutil # ...
user1338062
  • 9,351
  • 3
  • 54
  • 56