Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am on a mac and am trying to install the Google Cloud SDK (including the gcloud command line utility) using this command in terminal

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

as seen at https://cloud.google.com/sdk/

It got all the way to the end and finished but even after I restarted my shell, the gcloud command still says it's not found.

Why isn't this installation working?

Which shell are you using? The installer prompts about updating your .bashrc file, but does not (yet) work with zsh or other shells. zsh support in the installer is on the way. Did you answer y when the installer prompted Modify profile to update your $PATH and enable bash completion? (Y/n)?? – Zachary Newman Jun 24, 2015 at 22:14 Actually yes, I saw that, but it didn't actually prompt me. It didn't wait for my response, so I didn't get to say YES. Therefore, the installer didn't do that step. I'm wondering how to make a more permanent fix now, because it seems like my fix only worked for the one time and I had to do it again today to fix it again. Suggestions? – jazz Jun 25, 2015 at 18:47 Actually I just re-installed it this time and the prompt worked, so now I'm all good. Thanks – jazz Jun 25, 2015 at 19:11 When I installed gcloud the install modified the profile (e.g. ~/.bash_profile) but it failed to reload it. Running source ~/.bash_profile fixed it. – nick Nov 26, 2016 at 16:42 following nicks notes, i ran source ~/.bashrc instead and it seemed to fix it for me since i didnt have a bash_profile. – Andy Danger Gagne Dec 16, 2021 at 18:43

So below is my previous fix for this problem, but it turns out it isn't permanent. It works but every time you restart Terminal, you'd have to do the same thing which isn't practical.

So that is why I suggest you delete the current google-cloud-sdk directory, and just redo the installation. Be sure (as Zachary has mentioned) to answer yes (Y) to the prompt Modify profile to update your $PATH and enable bash completion? (Y/n).

Here is my old answer, but just redo the installation:

I had the same problem, gcloud wasn't working for me. But then, in the same directory as my google-cloud-sdk folder which I had just installed (my home directory), I found this file called test. Inside this test file I found two commands:

# The next line updates PATH for the Google Cloud SDK.
source '[path-to-my-home]/google-cloud-sdk/path.bash.inc'
# The next line enables bash completion for gcloud.
source '[path-to-my-home]/google-cloud-sdk/completion.bash.inc'

After I ran these two source commands in terminal, gcloud worked!

Well guys in my case i just forgot to close and open the terminal window after instalation.... hope this help any body :D – NFRiaCowboy Jun 12, 2017 at 22:52
  • Achieved file and drop in your folder

  • Open terminal, go to your folder with file and enter this command:

     ./google-cloud-sdk/install.sh
    
  • "Modify profile to update your $PATH and enable bash completion?"

  • Enter this path to modify:
    /Users/USERNAME_COMPUTER/.bashrc
  • After all install, enter this:

      source ~/.bashrc
    
  • Enter this to check install gcloud:

    gcloud - -version

  • Open new window terminal cmd+n DONT CLOSE OLD WINDOW and enter in new window gcloud version

    if: «command not found» go to step 9

    else: Congratulations GCloud work in terminal

  • Return to old window and enter echo $PATH and copy path to GCloud

  • Open BASH_PROFILE:

    open ~/.bash_profile
    
  • Enter path to new Bash:

    « export PATH="/Users/USERNAME_COMPUTER/google-cloud-sdk/bin:$PATH" »
    
  • Return to step 8

  • Only answer working with the new version, where the 'add variables to path' prompt is absent. – Standaa - Remember Monica Oct 10, 2017 at 17:51 In my case, it was export PATH="$HOME/google-cloud-sdk/bin:$PATH" as I had installed the SDK folder in my home directory. – Babajide M. Moibi Nov 11, 2020 at 11:35

    I had this issue today, and adding sudo to the install command fixed my issue on maxOS Sierra!

    sudo ./google-cloud-sdk/install.sh
                    you need to put the .zshrc when the installation program ask for the file bash that are using you. so you need to put some like this:    /Users/YOU-NAME-USER/.zshrc
    – Richard Rebeco
                    Oct 17, 2018 at 19:41
    

    I'm running zsh and found this gist very helpful: https://gist.github.com/dwchiang/10849350

    Edit the ~/.zshrc file to include these two lines:

    # The next line updates PATH for the Google Cloud SDK.
    source /Users/YOUR_USERNAME/google-cloud-sdk/path.zsh.inc
    # The next line enables zsh completion for gcloud.
    source /Users/YOUR_USERNAME/google-cloud-sdk/completion.zsh.inc
    

    This assumes you installed the package in your main directory from the official docs

    In my case, I switched the terminal from bash to zsh after I installed Google Cloud SDK, so it showed the 'zsh: command not found: gcloud' error.

    It's solved by running

    source ~/.zshrc
                    Note that all this does is to execute the .zshrc file which should have been executed when the terminal opened. So, the question is, why was it not executed? In my case, the reason was that as I downloaded the SDK it was placed on my Downloads directory where it was deleted at some point in time. Place the SDK in a folder where it's not going to be deleted, run the install.sh script again, and it will load it on startup every time.
    – Mike M
                    Dec 1, 2022 at 10:59
    

    I know this question has been answered, but here are my two cent. After installing gcloud, you need to restart the shell before you able to gcloud command.

    How you do this, mostly depends on the file you keep your shell configuration. Most files are .bashrc_profile, .bashrc, .zshrc.

    You can now restart with

    source ~/.bashrc_profile

    You can replace the file to the file you have.

    Or if you don't care the file you have, on Mac or linux you can restart the shell .

    exec -l $SHELL

    and find the lines to append to ~/.zshrc

    The lines to append can be obtained from the output of the previous command. For zsh users, It should be some like these:

    export CLOUDSDK_PYTHON="/usr/local/opt/python@3.8/libexec/bin/python"
    source "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc"
    source "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc"
    

    (or choose the proper ones from the command output depending un the Shell you are using)

    This nuance is specified on the gcloud brew page. Although I'm not sure if the CLOUDSDK_PYTHON variable needs to be exported – Domadin Jun 16, 2021 at 22:56
  • Open up a Terminal session.
  • In that session type: source .bash_profile and then press enter
  • Now, the gcloud command should work

    To launch it on MacOs Sierra, after install gcloud I modified my .bash_profile

    Original lines:

    # The next line updates PATH for the Google Cloud SDK.
    if [ -f '/Users/alejandro/google-cloud-sdk/path.bash.inc' ]; then . '/Users/alejandro/google-cloud-sdk/path.bash.inc'; fi
    # The next line enables shell command completion for gcloud.
    if [ -f '/Users/alejandro/google-cloud-sdk/completion.bash.inc' ]; then . '/Users/alejandro/google-cloud-sdk/completion.bash.inc'; fi
    

    updated to:

    # The next line updates PATH for the Google Cloud SDK.
    if [ -f '/Users/alejandro/google-cloud-sdk/path.bash.inc' ]; then source '/Users/alejandro/google-cloud-sdk/path.bash.inc'; fi
    # The next line enables shell command completion for gcloud.
    if [ -f '/Users/alejandro/google-cloud-sdk/completion.bash.inc' ]; then source '/Users/alejandro/google-cloud-sdk/completion.bash.inc'; fi
    

    Restart the terminal and all become to work as expected!

    This worked for me :

    After saying Y to Modify profile to update your $PATH and enable bash completion? (Y/n)?

    Google initiation is prompting this : Enter a path to an rc file to update, or leave blank to use and the default path was : [/Users/MY_USERSAME/.bash_profile]: but instead of pressing enter, I wrote : /Users/MY_USERNAME/.bashrc to change the path.

    This would overwrite the default location that Google suggest.

    Then, I only had to do source ~/.bashrc and everything works now!

    This fixed my problem. I was typing ~/.bash_profile and the installation wasn't not updating the path, but also not outputting an error. – Jude Osborn Mar 16, 2017 at 0:00

    After inspecting the installation zip by running ./google-cloud-sdk/install.sh --help, the parameter --path-update worked for me. Use it as follows,

    ./google-cloud-sdk/install.sh --path-update true
    

    It will automatically add the PATH update to the .bashrc (see --rc-path parameter for different rc files). Add the --quiet parameter for no interactivity.

    I found incorrect if-fi statements in my ~/.bash_profile (no if condition in the next block)

    source '/Users/yorko/google-cloud-sdk/path.bash.inc'

    I just had to remove "fi" and run "source ~/.bash_profile" to make it work.

  • Edit your .zshrc and add the following

    # The next line updates PATH for the Google Cloud SDK.
    source /Users/USER_NAME/google-cloud-sdk/path.zsh.inc
    # The next line enables zsh completion for gcloud.
    source /Users/USER_NAME/google-cloud-sdk/completion.zsh.inc
    
  • Create new file named path.zsh.inc under your home directory(/Users/USER_NAME/):

    script_link="$( readlink "$0" )" || script_link="$0"
    apparent_sdk_dir="${script_link%/*}"
    if [ "$apparent_sdk_dir" == "$script_link" ]; then
     apparent_sdk_dir=.
    sdk_dir="$( cd -P "$apparent_sdk_dir" && pwd -P )"
    bin_path="$sdk_dir/bin"
    export PATH=$bin_path:$PATH
    

    Checkout more @ Official Docs

    Using .zsh shell you can just try to add glcoud in plugin list in the ~/.zshrc file.

    plugins=(
      gcloud
    

    If that doesn't work, try this: (updated Krishna's answer)

  • Update the ~/.zshrc file
  • # Updates PATH for the Google Cloud SDK.
    source /Users/austris/google-cloud-sdk/path.zsh.inc
    # Enables zsh completion for gcloud.
    source /Users/austris/google-cloud-sdk/completion.zsh.inc
    
  • Update the google-cloud-sdk/path.zsh.inc file with following
  • script_link="$( readlink "$0" )" || script_link="$0" 
    apparent_sdk_dir="${script_link%/*}" 
    if [[ "$apparent_sdk_dir" == "$script_link" ]]; then
      apparent_sdk_dir=. 
    sdk_dir="$( cd -P "$apparent_sdk_dir" && pwd -P )" 
    bin_path="$sdk_dir/bin" 
    export PATH=$bin_path:$PATH
    

    *double square brackets at the third line were missing from the original answer

    If you are running ZSH shell in MacOS you should rerun the installation and when you be asked for this question:

    Modify profile to update your $PATH and enable shell command 
    completion?
    

    answer YES

    Enter a path to an rc file to update, or leave blank to use 
        [/Users/your_user/.bash_profile]:
    

    answer(your zshrc path): /Users/your_user/.zshrc

    Restart Terminal and that's all.

    In addition to the above answers, depending on your distro, it may be necessary to execute the bash command from the command line before calling your gsutil command. This is the case for distros that have tcsh or other shell as the default. By typing "bash" the source is changed to the .bashrc file and the file is executed.

    # Step 1
    # Step 2
    gsutil 
    #Step 3: profit!
    

    Post installation instructions are not clear:

    ==> Source [/.../google-cloud-sdk/completion.bash.inc] in your profile to enable shell command completion for gcloud.
    ==> Source [/.../google-cloud-sdk/path.bash.inc] in your profile to add the Google Cloud SDK command line tools to your $PATH.
    

    I had to actually add the following lines of code in my .bash_profile for gcloud to work:

    source '/.../google-cloud-sdk/completion.bash.inc'
    source '/.../google-cloud-sdk/path.bash.inc'
    

    Once it is done try installing any package by glcloud command:

    gcloud components install app-engine-php
    

    It won't show the error.

    The cause of my installation failure:

  • I am running a zsh terminal and the install.sh inserts path.bash.inc into my .bash_profile
  • cd [whereever]/google-cloud-sdk && ./install.sh
  • vi ~/.bash_profile
  • replace all instances of path.bash.inc with path.zsh.inc
  • os config:

  • macOS Catalina
  • https://stackoverflow.com/a/61491744/1989698
  • and then

    Enter a path to an rc file to update, or leave blank to use 
    [/Users/uer/.bash_profile]:  "/usr/lib/google-cloud-sdk/bin:$PATH"
    

    result:

    ["/usr/lib/google-cloud-sdk/bin:$PATH"] has been updated.
            

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

  •