-bash: gcloud: 在 Mac 上找不到命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46144267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
-bash: gcloud: command not found on Mac
提问by Shane O'Seasnain
I'm following the Quickstart for Mac OS Xto install the cloud SDK. Following the steps exactly,
我正在按照Mac OS X的快速入门安装云 SDK。严格按照步骤,
1) python -V
returns "Python 2.7.10"
1)python -V
返回“Python 2.7.10”
2) Download and extract using ./install.sh
the 64bit version of the SDK in google-cloud-sdk returns...
2)./install.sh
在google-cloud-sdk中使用64位版本的SDK下载并解压返回...
Welcome to the Google Cloud SDK!
To help improve the quality of this product, we collect anonymized usage data
and anonymized stacktraces when crashes are encountered; additional information
is available at <https://cloud.google.com/sdk/usage-statistics>. You may choose
to opt out of this collection now (by choosing 'N' at the below prompt), or at
any time in the future by running the following command:
gcloud config set disable_usage_reporting true
Do you want to help improve the Google Cloud SDK (Y/n)? Y
Your current Cloud SDK version is: 170.0.1
The latest available version is: 170.0.1
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Components │
├───────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬───────────┤
│ Status │ Name │ ID │ Size │
├───────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼───────────┤
│ Not Installed │ App Engine Go Extensions │ app-engine-go │ 97.7 MiB │
│ Not Installed │ Cloud Bigtable Command Line Tool │ cbt │ 4.0 MiB │
│ Not Installed │ Cloud Bigtable Emulator │ bigtable │ 3.5 MiB │
│ Not Installed │ Cloud Datalab Command Line Tool │ datalab │ < 1 MiB │
│ Not Installed │ Cloud Datastore Emulator │ cloud-datastore-emulator │ 15.4 MiB │
│ Not Installed │ Cloud Datastore Emulator (Legacy) │ gcd-emulator │ 38.1 MiB │
│ Not Installed │ Cloud Pub/Sub Emulator │ pubsub-emulator │ 33.2 MiB │
│ Not Installed │ Emulator Reverse Proxy │ emulator-reverse-proxy │ 14.5 MiB │
│ Not Installed │ Google Container Local Builder │ container-builder-local │ 3.7 MiB │
│ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr │ 2.2 MiB │
│ Not Installed │ gcloud Alpha Commands │ alpha │ < 1 MiB │
│ Not Installed │ gcloud Beta Commands │ beta │ < 1 MiB │
│ Not Installed │ gcloud app Java Extensions │ app-engine-java │ 128.1 MiB │
│ Not Installed │ gcloud app PHP Extensions (Mac OS X) │ app-engine-php-darwin │ 21.9 MiB │
│ Not Installed │ gcloud app Python Extensions │ app-engine-python │ 6.5 MiB │
│ Not Installed │ kubectl │ kubectl │ 15.9 MiB │
│ Installed │ BigQuery Command Line Tool │ bq │ < 1 MiB │
│ Installed │ Cloud SDK Core Libraries │ core │ 6.7 MiB │
│ Installed │ Cloud Storage Command Line Tool │ gsutil │ 3.0 MiB │
└───────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴───────────┘
To install or remove components at your current SDK version [170.0.1], run:
$ gcloud components install COMPONENT_ID
$ gcloud components remove COMPONENT_ID
To update your SDK installation to the latest version [170.0.1], run:
$ gcloud components update
==> Source [/Users/shaneoseasnain/Desktop/google-cloud-sdk/completion.bash.inc] in your profile to enable shell command completion for gcloud.
==> Source [/Users/shaneoseasnain/Desktop/google-cloud-sdk/path.bash.inc] in your profile to add the Google Cloud SDK command line tools to your $PATH.
For more information on how to get started, please visit:
https://cloud.google.com/sdk/docs/quickstarts
3) I've restarted the terminal and run gcloud init
from inside google-cloud-sdk. This returns "command not found
." If I run ls
, I see the following directory structure:
3)我重新启动了终端并gcloud init
从 google-cloud-sdk 内部运行。这将返回“ command not found
。” 如果我运行ls
,我会看到以下目录结构:
LICENSE completion.zsh.inc path.fish.inc
README deb path.zsh.inc
RELEASE_NOTES install.bat platform
VERSION install.sh properties
bin lib rpm
completion.bash.inc path.bash.inc
4) I've tried to run gcloud init
inside bin
as well, but get the same problem, command not found
.
4) 我也试过在gcloud init
里面跑bin
,但遇到同样的问题,command not found
.
The only other suggestions I can see from the install guide are "enable command-completion in your bash shell, and/or enable usage reporting." I'm not sure how to do this but command completion and reporting don't look like they should be related to this problem. There is a lot written about command not found
but they relate to other problems where, for example, gcloud has stopped working after a while or problems in older versions. Has anyone a tip how to get the cloud sdk working?
我可以从安装指南中看到的唯一其他建议是“在 bash shell 中启用命令完成,和/或启用使用情况报告”。我不确定如何执行此操作,但命令完成和报告看起来与此问题无关。写了很多,command not found
但它们与其他问题有关,例如,gcloud 一段时间后停止工作或旧版本出现问题。有没有人知道如何让云 sdk 工作?
Thanks
谢谢
回答by LiweiZ
I had the same issue. A lazy and quick fix for this is to just run:
我遇到过同样的问题。一个懒惰而快速的解决方法是运行:
brew cask install google-cloud-sdk
brew cask install google-cloud-sdk
Found by googling.
通过谷歌搜索找到。
回答by Zachary Newman
The gcloud
executable lives in google-cloud-sdk/bin
–to run gcloud. You'll need to either:
该gcloud
可执行生活google-cloud-sdk/bin
-to执行gcloud。您需要:
- Add this directory to your $PATH. In particular, adding the line
source /Users/shaneoseasnain/Desktop/google-cloud-sdk/path.bash.inc
to your.bash_profile
file (more detail on what this file does and how to pick one) will do the trick. Specify the full path to the
gcloud
executable when you run it. In your case, this is/Users/shaneoseasnain/Desktop/google-cloud-sdk/bin/gcloud
. So for example:$ /Users/shaneoseasnain/Desktop/google-cloud-sdk/bin/gcloud init
- 将此目录添加到您的$PATH。特别是,将这一行添加
source /Users/shaneoseasnain/Desktop/google-cloud-sdk/path.bash.inc
到您的.bash_profile
文件中(有关此文件的作用以及如何选择一个文件的更多详细信息)可以解决问题。 gcloud
运行时指定可执行文件的完整路径。在您的情况下,这是/Users/shaneoseasnain/Desktop/google-cloud-sdk/bin/gcloud
. 例如:$ /Users/shaneoseasnain/Desktop/google-cloud-sdk/bin/gcloud init
The pertinent part of the quickstart(emphasis added):
快速入门的相关部分(已添加重点):
Run the install script to add Cloud SDK tools to your path, enable command-completion in your bash shell, and/or enable usage reporting:
运行安装脚本以将 Cloud SDK 工具添加到您的路径、在 bash shell 中启用命令完成和/或启用使用情况报告:
As to why the install script didn't work, I can't say. Please file an issueand we'll investigate.
至于为什么安装脚本不起作用,我不能说。请提出问题,我们将进行调查。
回答by connVerze
TL;DR- follow the Interactive installersection of Installing Cloud SDKand the SDK will install correctly.
TL;DR- 按照安装 Cloud SDK的交互式安装程序部分,SDK 将正确安装。
However, there is a real issue here which I believe is related to missing environment variables:
但是,这里有一个真正的问题,我认为这与缺少环境变量有关:
At first, I followed Quickstart for Mac OS Xas well in order to install the Google Cloud SDK for the 'Mac OS X (x86_64) Platform'. This reproduced the exact same results as Shaneoutlined in his question above. Here are some more details:
起初,我也遵循了 Mac OS X 快速入门,以便为“Mac OS X (x86_64) 平台”安装 Google Cloud SDK。这再现了与Shane在上述问题中概述的完全相同的结果。以下是更多详细信息:
- Clean install of macOS Sierra 10.12.6 (latest) on a 2017 MacBook Pro.
- Google Cloud SDK version 173.0.0. Specifically: google-cloud-sdk-173.0.0-darwin-x86_64.tar.gz which is the latest at the time of this writing and the one pointed to by the quickstart guide.
- 在 2017 款 MacBook Pro 上全新安装 macOS Sierra 10.12.6(最新)。
- Google Cloud SDK 版本 173.0.0。具体来说:google-cloud-sdk-173.0.0-darwin-x86_64.tar.gz,这是撰写本文时的最新版本,也是快速入门指南中提到的版本。
I was able to further pinpoint the problem in step 4 of the 'Before you begin' section of Quick Start for Mac OS X:
我能够在 Mac OS X 快速入门的“开始之前”部分的第 4 步中进一步查明问题:
Set up the Cloud SDK for use. If you're having trouble getting the gcloud command to work, ensure your $PATH is defined appropriately. Run the install script to add Cloud SDK tools to your path, enable command-completion in your bash shell, and/or enable usage reporting:
./google-cloud-sdk/install.sh
设置 Cloud SDK 以供使用。如果您在使用 gcloud 命令时遇到问题,请确保正确定义了 $PATH。运行安装脚本以将 Cloud SDK 工具添加到您的路径、在 bash shell 中启用命令完成和/或启用使用情况报告:
./google-cloud-sdk/install.sh
'install.sh' invokes 'install.py' which at some point calls isatty()in order to find out whether the installation process was run from the shell which means it should be interactive and prompt the user for some information. For some reason, isatty()returns Falseinstead of True! This causes to script to fall through non-interactivelyand - because 'install.sh' was invoked without arguments - Fail.
“install.sh”调用“install.py”,它在某个时候调用isatty()以确定安装过程是否从 shell 运行,这意味着它应该是交互式的并提示用户提供一些信息。出于某种原因,isatty()返回False而不是True!这会导致脚本以非交互方式失败,并且 - 因为 'install.sh' 是在没有参数的情况下调用的 - Fail。
回答by K_Sg
The following worked for me:
以下对我有用:
- I moved the installer unzipped package to the ~ directory.
- And then after running ./google-cloud-sdk/install.sh
- I restarted the terminal again and ran 'gcloud init' and it worked.
- 我将安装程序解压缩包移动到 ~ 目录。
- 然后在运行 ./google-cloud-sdk/install.sh 之后
- 我再次重新启动终端并运行“gcloud init”并且它起作用了。
回答by Hamid Hoseini
Sometimes, after installation, you need just restart your terminal. that's it :)
有时,安装后,您只需重新启动终端即可。就是这样 :)
take a look at here: Quickstart for macOS
看看这里:macOS 快速入门
回答by Frances He
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:
以下文章提出的解决方案对我有用:
http://www.javatronic.fr/tips/2014/10/17/installing_google_cloud_sdk_on_ubuntu_with_oh-my-zsh.html
http://www.javatronic.fr/tips/2014/10/17/installing_google_cloud_sdk_on_ubuntu_with_oh-my-zsh.html
回答by lalyos
for me that was the fix:
对我来说,这就是解决办法:
mkdir -p $sdk_dir/.install/
tl;dr;
tl;博士;
It seems that the python library is locating the sdk_rootby searching for an .install
directory. See the config.pyand the definition of CLOUDSDK_STATE_DIR
似乎python库通过搜索目录来定位sdk_root.install
。参见config.py和CLOUDSDK_STATE_DIR的定义
回答by lalyos
Follow this steps:
请按照以下步骤操作:
Press Command+Space and type Terminal and press enter/return key.
Run in Terminal app:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null ; brew install caskroom/cask/brew-cask 2> /dev/null
按 Command+Space 并键入 Terminal,然后按 Enter/Return 键。
在终端应用程序中运行:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null ; brew install caskroom/cask/brew-cask 2> /dev/null
If the screen prompts you to enter a password, please enter your Mac's user password to continue. When you type the password, it won't be displayed on screen, but the system would accept it. So just type your password and press ENTER/RETURN key. Then wait for the command to finish.
如果屏幕提示您输入密码,请输入您 Mac 的用户密码以继续。当您输入密码时,它不会显示在屏幕上,但系统会接受它。所以只需输入您的密码,然后按 ENTER/RETURN 键。然后等待命令完成。
Run
brew cask install google-cloud-sdk
跑
brew cask 安装 google-cloud-sdk
Reference:
参考: