33

I need to add the Google Cloud SDK in the PATH. So I need the path to where is installed. Is there any gcloud ... command which gives me this information?

If not I have to go through the symlink in which gcloud, etc.

Any cleaner solution for this problem?

Stephen Weinberg
  • 51,320
  • 14
  • 134
  • 113
Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168

3 Answers3

70

The following command will give you the information you're looking for:

$ gcloud info --format="value(installation.sdk_root)"
/path/to/google-cloud-sdk/

You need to append /bin.

You also have lots of other paths available: config.paths.global_config_dir, installation.sdk_root, and so on. Look at the output of gcloud info --format=json for all available properties to query.

Zachary Newman
  • 20,014
  • 4
  • 39
  • 37
  • The `config.paths` section no longer contains entries for `logs_dir`, `sdk_root` or `sdk_bin_path`. There is however a `installation.sdk_root` property now. Simply append `/bin/` to get the bin path or `/platform/google_appengine/` for the App Engine SDK path. I'm using Google Cloud SDK [158.0.0]. I also found that on Windows you need to omit the single quotes in the format expression. – maltem-za Jun 14 '17 at 15:07
  • Thanks for the note; I've updated my answer. Yeah, Windows is a little different; double quotes should work on all platforms. – Zachary Newman Jun 14 '17 at 18:04
8

I used:

dirname $(which gcloud)

And worked like a charm

EliuX
  • 11,389
  • 6
  • 45
  • 40
  • 2
    If gcloud is installed via apt-get on debian this will result in `/usr/bin` instead of `/usr/lib/google-cloud-sdk` – Paul Nov 24 '17 at 10:47
  • 2
    It works well, you can even confirm the binary of the gcloud file is there with `ls $(dirname $(which gcloud))` – EliuX Nov 24 '17 at 22:06
  • If you installed from source it does, but not if you installed via apt-get. On debian and Ubuntu "which gcloud" resolved to /usr/bin/gcloud, which is a symlink to /usr/lib/gcloud-sdk/bin/gcloud. So in a binary installation this does not work. – Paul Nov 25 '17 at 21:44
  • how do you do that on windows? – Sunny Sharma May 18 '18 at 12:34
  • I use to use Powershell and just run `bash` and it works pretty much like any Unix based OS. – EliuX May 19 '18 at 23:13
  • The answer this gives you may be misleading. On OSX, installing gcloud via brew shows that gcloud is `/usr/local/bin/gcloud`, but it's a symlink to where gcloud is _actually_ installed. – Mr. Llama Apr 14 '19 at 18:49
  • Sure, you can also use the Git bash in Windows – EliuX Nov 26 '19 at 15:39
2

As of March 2022, the gcloud sdk link indicates you can have the SDK for client libraries Java, Python, Node.js, Ruby, .Net and Php.

In addition you can have the CLI too. If you have installed the CLI, part of the ( optional ) install process is to add the gcloud binary path to your PATH thus you can find it.

This script is called path.bash.inc, path.zsh.inc etc and depending on what your default shell is it will run the correct path.your_shell.inc file. If you have never run that, then it is possible your gcloud was installed in a directory that you lost track of.

If that is the case, then you have to simply run a "find" from the root

find / -name gcloud -type f -ls 2>/dev/zero

This contrasts with

  1. AWS cli, that gets installed into system common PATH directory like /usr/local/bin on Mac

2 AZ cli, that gets installed using homebrew on Mac - under /opt/homebrew/bin path - which, if you used a Mac, already is in your Path.

Sumit S
  • 516
  • 5
  • 17