Google cloud SDK installation error: Could not update [/Users/username/.bash_profile]. Ensure you have write access to this location

I am getting the above error while installing Google cloud sdk.

I entered below command in terminal:

curl https://sdk.cloud.google.com | bash

Thanks

Upvotes: 5

Views: 1314

Answers (3)

eriel marimon
eriel marimon

Reputation: 1380

TL;DR (copy and paste)

curl https://sdk.cloud.google.com | sudo bash

Explanation

On my first answer I noted that

sudo curl https://sdk.cloud.google.com | bash

didn't work, adding the sudo in front of bash seems to have the intended effect, rather than on the curl command. This should be simpler than changing ownership back and forth.

Upvotes: 0

eriel marimon
eriel marimon

Reputation: 1380

TL;DR (copy and paste in 2 steps, )

Step 1 (gcloud will prompt for input):

sudo chown $(whoami):staff ~/.bash_profile
curl https://sdk.cloud.google.com | bash

Step 2:

sudo chown root:staff ~/.bash_profile
source ~/.bash_profile

Explanation:

~/.bash_profile is owned by the rootuser, so it requires sudo and therefore the root password. The command curl https://sdk.cloud.google.com | bash does not have permission to edit it. My solution here was to change ownership of the file for the installation of gcloud and then revert it back to root after the installation was completed.

  1. Change ownership of the file sudo chown $(whoami):staff ~/.bash_profile

    • This command will probably prompt for password
    • $(whoami) will be replaced by the currently logged in user.
    • staff is just the already existing group
  2. Run installation command and proceed to respond input prompts $ curl https://sdk.cloud.google.com | bash
  3. Reset root ownership to the profile for security reasons sudo chown root:staff ~/.bash_profile
  4. Reload shell to make gcloud commands available $ source ~/.bash_profile

Important Note

I tried sudo curl https://sdk.cloud.google.com | bash but it did not work for some reason.

Upvotes: 3

Lopson
Lopson

Reputation: 1217

This most likely happened when the SDK's installation script attempted to modify your .bashrc in order to add gcloud (and others) to your profile's PATH environment variable. The script attempted to change the file, but didn't have enough permissions to do it, thus failed. I recommend making sure you or the user installing the SDK can modify their own .bashrc file.

Upvotes: 0

Related Questions