gcloud command not found - while installing Google

2019-01-30 21:37发布

问题:

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?

回答1:

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!


回答2:

Same here, I try

source ~/.bashrc

Then, It worked



回答3:

On Mac/Linux, you'll need to enter the following entry in your ~/.bashrc:

export PATH="/usr/lib/google-cloud-sdk/bin:$PATH"


回答4:

This one worked for me:

source ~/.bash_profile


回答5:

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

sudo ./google-cloud-sdk/install.sh


回答6:

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



回答7:

When installing the SDK I used this method:

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

When using this method from the original author make sure you have accepted the security preferences in your mac settings to allow apps downloaded from app store and identified developers.



回答8:

I had to source my bash_profile file. To do so,

  1. Open up a Terminal session.
  2. In that session type: source .bash_profile and then press enter

Now, the gcloud command should work



回答9:

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!



回答10:

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



回答11:

You just have to execute this command as root

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

Restart the terminal and that's it. Now all commands should be executed as root



回答12:

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'

fi

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



回答13:

If running

source ~/.bashrc

results in "No such file or directory"

On windows:

  1. Go to c/Users/
  2. While holding shift, right-click .bashrc file and select "Copy as path"
  3. In bash: source <pasteCopiedPathHere> -> for example: source "C:\Users\John\.bashhrc"


回答14:

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'


回答15:

I had the same problem and it was because the ~/.bash_profile had invalid fi statements.

The fix:

  1. Execute command sudo nano ~/.bash_profile
  2. Removed closing fi statements (the ones missing an opening if)
  3. Save .bash_profile changes
  4. Execute command source ~/.bash_profile


回答16:

$ sudo su
$ /opt/google-appengine-sdk/bin/gcloud components update
$ su <yourusername>


回答17:

Now after running install.sh in Mac OS, google itself giving the information to run completion.bash.inc and path.bash.inc.

If you're using zsh terminal, it'll ask you to run completion.zsh.inc and path.zsh.inc. Please see the image below



回答18:

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

and

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.



回答19:

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!



回答20:

How to install GCloud and Always Works after Restart On Mac OS HIGH Sierra:

  1. Download install package Here

  2. Achieved file and drop in your folder

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

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

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

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

    gcloud - -version

  8. 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

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

  10. Open BASH_PROFILE:

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

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