gcloud command not found - while installing Google Cloud SDK
Asked Answered
A

41

211

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?

Akee answered 24/6, 2015 at 21:21 Comment(5)
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)??Debris
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?Akee
Actually I just re-installed it this time and the prompt worked, so now I'm all good. ThanksAkee
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.Southworth
following nicks notes, i ran source ~/.bashrc instead and it seemed to fix it for me since i didnt have a bash_profile.Cobol
A
218

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!

Akee answered 24/6, 2015 at 21:21 Comment(8)
For zsh, there are corresponding path.zsh.inc and completion.zsh.inc files.Debris
Well guys in my case i just forgot to close and open the terminal window after instalation.... hope this help any body :DDestructor
Unfortunately, this is no longer a question in the latest install.shElectricity
Current gcloud install package has somehow forked up this step.Katt
gcloud has shell script to help with this now after you download the gcloud tar.gz from their site, then run ./google-cloud-sdk/install.sh. which will basically do the above commands for you when you follow the steps cloud.google.com/sdk/docs/quickstart-macosPiscine
The QuickStart for macOS doesn't add the source command just adds it to the path. Which is a problem. This solution helped me. Thanks!Height
Won't work for me because despite installing it the same way it disappears after install, completely vanishing, there is no google-cloud-sdk dir.Pion
those source files are copied into the bashrc file by the end of the installation. so source ~/.bashrc(rc file, wherever it is on the disk) should help you get goingI
M
83

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

Matronly answered 21/9, 2018 at 6:59 Comment(1)
Thank you so much this did help :)Moloch
M
81

Same here, I try

source ~/.bashrc

Then, It worked

Muskeg answered 9/9, 2015 at 9:1 Comment(2)
No such file or directoryGrenadines
source ~/.zshrc for macOS CATALINAVaulted
C
47

This one worked for me:

source ~/.bash_profile
Cashbook answered 16/10, 2016 at 17:29 Comment(2)
Worked for me as wellEnantiomorph
first export PATH="/usr/lib/google-cloud-sdk/bin:$PATH" then this command above.Mcsweeney
R
33

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

export PATH="/usr/lib/google-cloud-sdk/bin:$PATH"
Rheumatism answered 17/1, 2017 at 1:4 Comment(5)
It worked on mac as well. The PATH variable will need to be set.Coachwhip
@ParthBhoiwala Thanks for letting me know, I've updated the answer. :)Rheumatism
Only answer working with the new version, where the 'add variables to path' prompt is absent.Dissolve
This one worked for me. My installation didn't update .bashrc on its own.Tia
In my case, it was export PATH="$HOME/google-cloud-sdk/bin:$PATH" as I had installed the SDK folder in my home directory.Cataldo
C
28

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

Carder answered 4/12, 2017 at 23:44 Comment(0)
W
24

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

sudo ./google-cloud-sdk/install.sh
Whoop answered 1/12, 2017 at 23:20 Comment(3)
This is the only thing that helped me on Sierra - none of the other answers worked.Index
This also fixed my problem on macOS v10.13 "High Sierra"Perplexed
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/.zshrcAlar
B
24

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
Bifid answered 19/11, 2021 at 17:22 Comment(1)
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.Chatterton
D
22

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.

Drier answered 18/2, 2018 at 22:19 Comment(2)
This was very helpful. Thanks!Acquittance
I had to add the sudo in frontGarygarza
S
16

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

Sadowski answered 9/12, 2017 at 17:12 Comment(0)
M
16

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

Malamute answered 15/12, 2017 at 12:8 Comment(0)
M
16

You have to add the command to the path

Run

brew info --cask google-cloud-sdk

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/[email protected]/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)

Merri answered 18/11, 2020 at 22:28 Comment(2)
This nuance is specified on the gcloud brew page. Although I'm not sure if the CLOUDSDK_PYTHON variable needs to be exportedInhale
Very helpful. Thank youStrander
L
9

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

Lazulite answered 5/9, 2015 at 18:17 Comment(0)
E
7

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!

Expediential answered 22/11, 2018 at 6:1 Comment(1)
When I do this, and run source ~/.zshrc, I get this error: /Users/talaljawaid/.zshrc:.:40: operation not permitted: /Users/talaljawaid/Downloads/google-cloud-sdk/path.zsh.inc /Users/talaljawaid/.zshrc:.:43: operation not permitted: /Users/talaljawaid/Downloads/google-cloud-sdk/completion.zsh.incInnocence
C
7

for oh-my-zsh run on terminal after install

source ~/.zshrc
Contortive answered 23/6, 2022 at 19:48 Comment(0)
G
6

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!

Goebbels answered 28/10, 2016 at 16:35 Comment(1)
This fixed my problem. I was typing ~/.bash_profile and the installation wasn't not updating the path, but also not outputting an error.Jennee
R
5

If you're a macOS homebrew zsh user:

  1. brew cask install google-cloud-sdk

  2. Update your ~/.zshrc:

plugins=(
  ...
  gcloud
)
  1. Open new shell.
Rippy answered 13/12, 2020 at 20:5 Comment(0)
J
4

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)

  1. 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
  1. 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=. 
fi
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

Jedthus answered 30/7, 2020 at 8:15 Comment(0)
U
4

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.

Uprush answered 10/8, 2021 at 23:21 Comment(0)
G
4

Tested on Mac

1. Installation

If did this already -> skip this step

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

2. Enable gcloud command line

source ~/.zshrc

If not works, try below

source ~/.bashrc

If not works, try below

source ~/.bash_profile

Hope this help!

Gabriello answered 18/4, 2023 at 9:57 Comment(1)
Thank-you for not assuming anything and listing all the possible alternates.Starrstarred
V
3

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.

Variform answered 2/10, 2016 at 10:58 Comment(0)
R
3

If you are on MAC OS and using .zsh shell then do the following:

  1. 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
    
  2. 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=.
    fi
    sdk_dir="$( cd -P "$apparent_sdk_dir" && pwd -P )"
    bin_path="$sdk_dir/bin"
    export PATH=$bin_path:$PATH
    

Checkout more @ Official Docs

Rupertruperta answered 25/11, 2019 at 9:28 Comment(0)
M
2

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"
Mythopoeic answered 4/5, 2017 at 15:12 Comment(0)
S
2

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.

Seaport answered 3/11, 2018 at 16:53 Comment(0)
V
2

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
bash
# Step 2
gsutil 
#Step 3: profit!
View answered 24/8, 2020 at 23:22 Comment(0)
P
2
sudo ./google-cloud-sdk/install.sh

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.
Palatalized answered 19/8, 2021 at 15:15 Comment(0)
M
2

If you are using zsh with Mac, after installation and initialization, you just need source ~./zshrc to apply the changes.

Mathre answered 20/9, 2021 at 9:24 Comment(0)
D
1

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'
Dorthydortmund answered 1/12, 2017 at 14:21 Comment(0)
D
1
sudo ./google-cloud-sdk/install.sh

I ran this in the root directory and it worked. I'm running macOS Mojave Version 10.14.3.

Doiron answered 25/2, 2019 at 23:42 Comment(0)
B
1

Try doing this command on Ubuntu/Linux:

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

Close the terminal or open a new window as the log says:

==> Start a new shell for the changes to take effect.

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

gcloud components install app-engine-php

It won't show the error.

Bugaboo answered 24/7, 2019 at 9:47 Comment(0)
C
1

The cause of my installation failure:

  • I am running a zsh terminal and the install.sh inserts path.bash.inc into my .bash_profile

fix:

  1. cd [whereever]/google-cloud-sdk && ./install.sh
  2. vi ~/.bash_profile
  3. replace all instances of path.bash.inc with path.zsh.inc

os config:

  • macOS Catalina
  • zsh

ref:

Christenechristening answered 17/12, 2020 at 23:7 Comment(0)
F
1

if you have installed google-cloud-sdk via snap, you have to modify path vaiable.Add snap directory to PATH as export PATH=$PATH:/snap/bin This worked for me.

Filature answered 12/11, 2021 at 17:4 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Deshawndesi
U
1

If using zsh , source

source ~/.zshrc

worked for me.

Unflinching answered 3/11, 2023 at 10:29 Comment(0)
E
0

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
Emit answered 5/10, 2016 at 17:50 Comment(0)
S
0
$ sudo su
$ /opt/google-appengine-sdk/bin/gcloud components update
$ su <yourusername>
Sumrall answered 8/10, 2016 at 14:53 Comment(0)
L
0

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

enter image description here

Lentamente answered 7/12, 2017 at 0:37 Comment(0)
S
0

I had a very different story here that turned out to be caused by my Python virtual environments.

Somewhere in the middle of running curl https://sdk.cloud.google.com | bash, I was getting error:

~/google-cloud-sdk/install.sh
Welcome to the Google Cloud SDK!
pyenv: python2: command not found

The `python2' command exists in these Python versions:
  2.7.14
  miniconda2-latest

solution I've modified google-cloud-sdk/install.sh script:

# if CLOUDSDK_PYTHON is empty
if [ -z "$CLOUDSDK_PYTHON" ]; then
  # if python2 exists then plain python may point to a version != 2
  #if _cloudsdk_which python2 >/dev/null; then
  #  CLOUDSDK_PYTHON=python2
  if _cloudsdk_which python2.7 >/dev/null; then
    # this is what some OS X versions call their built-in Python
    CLOUDSDK_PYTHON=python2.7

and was able to run the installation successfully. However, I still need to activate my pyenv that has python2 command to run gcloud.

why so

If you look at the google-cloud-sdk/install.sh script, you'll see that it's actually checking for versions of Python in a very brute manner:

if [ -z "$CLOUDSDK_PYTHON" ]; then
  # if python2 exists then plain python may point to a version != 2
  if _cloudsdk_which python2 >/dev/null; then
    CLOUDSDK_PYTHON=python2

However, on my machine python2 doesn't point to Python binary, neither returns null. So the installation crashed.

Shemeka answered 15/5, 2019 at 21:47 Comment(0)
C
0

In short:

emacs -nw ~/.zshrc
And add following line at the beginning:

# The next line updates PATH for the Google Cloud SDK.
source '/home/lesaint/GOOGLE_CLOUD/google-cloud-sdk/path.zsh.inc'

#The next lines enables bash completion in Zsh for gcloud. 
autoload -U compinit compdef
compinit
source '/home/lesaint/GOOGLE_CLOUD/google-cloud-sdk/completion.zsh.inc'

The solution proposed by following article works for me:

Referencee: http://www.javatronic.fr/tips/2014/10/17/installing_google_cloud_sdk_on_ubuntu_with_oh-my-zsh.html

Check my solution: -bash: gcloud: command not found on Mac

Cardigan answered 13/3, 2020 at 12:2 Comment(0)
U
0

The thing that I did wrong was failing to choose the right download for my OS. I accidentally choose Apple Intel instead of Apple Silicon. Even though the installation appeared to work, I was unable to use the gcloud command. Once I deleted the folder and reinstalled the correct Apple Silicon version, everything worked fine for me.

Urine answered 17/12, 2021 at 18:3 Comment(0)
C
0

I faced a similar issue where after running ./install.sh and following all the steps, when I tried to check the version using gcloud --version

It gave me this error: zsh: command not found: gcloud

After going through all the answers here and searching through some websites, I found a webpage which provided the answer that worked for me. This is the link to the website: gcloud command not found – While Installing Google Cloud SDK

The basic gist is that once you go through the entire set up the .bash_profile is automatically modified, but sometimes that does not happen.

So at that time, rerun ./install.sh and when the prompt appears to change the path Modify profile to update your $PATH and enable shell command completion? Do you want to continue (Y/n)? enter Y and then set the path to ~/.profile.

This worked for me, I hope it does for you too. Have a nice day :))

Calces answered 13/8, 2023 at 2:14 Comment(0)
S
-1

It's worked for me:

  1. Download SDK from https://cloud.google.com/sdk/docs/install
  2. Extract the archive to my home directory (my home is "nintran")
  3. Run "./google-cloud-sdk/bin/gcloud init"
Saiga answered 29/1, 2021 at 10:27 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.