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