【问题标题】:-bash: gcloud: command not found on Mac-bash: gcloud: 在 Mac 上找不到命令
【发布时间】:2017-09-10 18:41:50
【问题描述】:

我正在关注Quickstart for Mac OS X 安装云SDK。完全按照步骤,

1) python -V 返回“Python 2.7.10”

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) 我已经重新启动终端并从 google-cloud-sdk 内部运行 gcloud init。这将返回“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) 我也尝试在 bin 中运行 gcloud init,但遇到了同样的问题,command not found

我可以从安装指南中看到的唯一其他建议是“在 bash shell 中启用命令完成,和/或启用使用情况报告”。我不确定如何执行此操作,但命令完成和报告看起来不应该与此问题相关。有很多关于 command not found 的文章,但它们与其他问题有关,例如 gcloud 在一段时间后停止工作或旧版本中的问题。有没有人提示如何让云 sdk 工作?

谢谢

【问题讨论】:

    标签: bash gcloud google-cloud-sdk


    【解决方案1】:

    我遇到了同样的问题。一个懒惰且快速的解决方法是运行:

    brew install --cask google-cloud-sdk

    通过谷歌搜索找到。

    【讨论】:

    • 没有为我修复它
    • 不知道这是否破坏了其他任何东西,但 gcloud 正在再次工作。 :)
    • 这并没有解决可能的路径问题,并且可以使用该命令复制此问题。如果您将路径变量添加到配置文件中,或者您是否注意到在运行此命令时添加了它,这将很有帮助。
    • brew install之后,我在这里找到了gcloud/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin
    【解决方案2】:

    对于 MAC 操作系统 - 使用 Homebrew

    brew install --cask google-cloud-sdk
    

    然后使用

     source "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc"
     source "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc"
    

    【讨论】:

    • 这对我在大苏尔有用。非常感谢。
    • 我在运行 source "$(brew --prefix)/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc" @ 时发现了以下问题987654323@
    • @nawazanjum 您可能遇到了问题,因为上面的说明适用于 zsh 并且您正在运行 bash。您可以尝试在上面的路径中将zsh 换成bash。通过 brew 安装后,它会打印:``` for bash users source "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.bash.inc" source "/usr/local/ Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.bash.inc" ```
    【解决方案3】:

    gcloud 可执行文件位于 google-cloud-sdk/bin 中——用于运行 gcloud。您需要:

    1. 将此目录添加到您的$PATH。特别是,将 source /Users/shaneoseasnain/Desktop/google-cloud-sdk/path.bash.inc 行添加到您的 .bash_profile 文件 (more detail on what this file does and how to pick one) 即可解决问题。
    2. 在运行时指定gcloud 可执行文件的完整路径。在您的情况下,这是/Users/shaneoseasnain/Desktop/google-cloud-sdk/bin/gcloud。比如:

      $ /Users/shaneoseasnain/Desktop/google-cloud-sdk/bin/gcloud init
      

    quickstart 的相关部分(已添加重点):

    运行安装脚本以将 Cloud SDK 工具添加到您的路径,在您的 bash shell 中启用命令完成,和/或启用使用情况报告:

    至于为什么安装脚本不起作用,我不能说。请file an issue,我们会进行调查。

    【讨论】:

      【解决方案4】:

      这是在 MacOS 上。我有同样的问题。我得到了gcloud: command not found

      brew install --cask google-cloud-sdk之后发现必须手动安装。

      • 首先,你会在google-cloud-sdk目录下找到install.sh,然后在终端下运行.../google-cloud-sdk/install.sh。就我而言,该文件位于/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk

      • 其次,运行/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/install.sh

      • 第三,由于您的bash 文件或zsh 文件已更新,将有一条消息指导您重新启动终端。

      • 第四,gcloud -v 测试启动新终端后 gcloud-cli 是否正常工作。

      【讨论】:

      • 我只做了第二步/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/install.sh 并按照提示进行操作
      【解决方案5】:

      简而言之:

      emacs -nw ~/.zshrc
      

      并在开头添加以下行:

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

      以下文章提出的解决方案对我有用:

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

      【讨论】:

      • 非常感谢这对我有用。我在 macOS Catalina 上
      • 我发现 this related comment 很有帮助
      【解决方案6】:

      TL;DR - 按照Installing Cloud SDK交互式安装程序部分操作,SDK 将正确安装。

      但是,我认为这里有一个真正的问题与缺少环境变量有关:

      起初,我也关注了Quickstart for Mac OS X,以便为“Mac OS X (x86_64) 平台”安装 Google Cloud SDK。这再现了与 Shane 在他上面的问题中概述的完全相同的结果。以下是更多细节:

      • 在 2017 MacBook Pro 上全新安装 macOS Sierra 10.12.6(最新)。
      • 谷歌云 SDK 版本 173.0.0。具体来说:google-cloud-sdk-173.0.0-darwin-x86_64.tar.gz,这是撰写本文时的最新版本,也是快速入门指南中指出的版本。

      我能够在 Mac OS X 快速入门的“开始之前”部分的第 4 步中进一步查明问题:

      设置 Cloud SDK 以供使用。如果您无法让 gcloud 命令正常工作,请确保您的 $PATH 定义正确。运行安装脚本以将 Cloud SDK 工具添加到您的路径,在您的 bash shell 中启用命令完成,和/或启用使用情况报告:

      ./google-cloud-sdk/install.sh

      'install.sh' 调用 'install.py',它在某些时候调用 isatty() 以确定安装过程是否从 shell 运行,这意味着它应该是交互式的并且提示用户一些信息。出于某种原因,isatty() 返回 False 而不是 True!这会导致脚本非交互式失败,并且 - 因为“install.sh”是在没有参数的情况下调用的 - 失败

      【讨论】:

        【解决方案7】:

        以下内容对我有用:

        • 我将安装程序解压缩包移动到 ~ 目录。
        • 然后在运行 ./google-cloud-sdk/install.sh 之后
        • 我再次重新启动终端并运行“gcloud init”,它运行正常。

        【讨论】:

        • 忘记重启终端了。
        【解决方案8】:

        有时,安装后,您只需重新启动终端即可。就是这样:)

        看看这里:Quickstart for macOS

        【讨论】:

          【解决方案9】:

          对我来说这是解决办法:

          mkdir -p $sdk_dir/.install/
          

          tl;博士;

          python 库似乎通过搜索.install 目录来定位 sdk_root。见config.pyCLOUDSDK_STATE_DIR的定义

          【讨论】:

            【解决方案10】:

            您的 google-cloud-sdk/bin 似乎没有出现在 PATH 中。

            从以下位置复制您当前的 PATH:

            echo $PATH
            

            现在将您的 google-cloud-sdk/bin 绝对路径添加到 PATH,不要忘记添加冒号 - ':',在添加新路径之前,它应该是这样的:

            PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/Users/user/google-cloud-sdk/bin
            

            【讨论】:

              【解决方案11】:

              按照以下步骤操作:

              1. Command+Space 并键入 Terminal 并按 enter/return 键。

              2. 在终端应用程序中运行:

              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
              

              如果屏幕提示您输入密码,请输入您的 Mac 用户密码以继续。当您输入密码时,它不会显示在屏幕上,但系统会接受。所以只需输入您的密码并按 ENTER/RETURN 键。然后等待命令完成。

              1. 运行
              brew cask install google-cloud-sdk
              

              参考:

              http://macappstore.org/google-cloud-sdk/

              【讨论】:

                猜你喜欢
                • 2019-09-04
                • 2012-10-03
                • 1970-01-01
                • 2016-06-23
                • 2016-06-05
                • 2015-08-08
                • 2014-10-10
                • 2016-02-20
                相关资源
                最近更新 更多