Why is my gcloud command suddenly very slow inside WSL2

Viewed 6547

When I run a simple command, it takes about 10 seconds to complete,

λ time gcloud version
Google Cloud SDK 293.0.0
beta 2019.05.17
bq 2.0.57
core 2020.05.15
gsutil 4.50

real    0m9.731s
user    0m0.735s
sys     0m1.690s

λ uname -a
Linux LAPTOP-U7E4CROH 4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

λ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal

I should note that I do not experience this slow behavior on the same laptop but within a git-bash environment - I only see this within WSL2 / Ubuntu.

I have tried to google around and I have found these two questions on SO, but they are not helping me:

Any ideas on how I can solve this?

3 Answers

I have the same issue and it turns out that in WSL 2 when I run gcloud it actually turn to use the gcloud installed on my Windows system. Somehow it is very slow if you run the Windows gcloud from WSL 2, which is also never my intention.

I just disable appending Windows PATH to my WSL PATH all together after this. But you know the root cause.

For the sake of completeness, to disable this feature, edit the /etc/wsl.conf to add the following section:

[interop]
appendWindowsPath = false

and terminate the WSL distro (wsl.exe --terminate <distro_name>) to make it immediately effective.

I had the same issue, resolved it by reinstalling the SDK: https://cloud.google.com/sdk/docs/downloads-interactive#linux

You must reinstall using 'Interactive installation', which replaces the previous installation and updates the PATH.

'Non-interactive (silent) deployment' does not seem to improve the issue.

Hope this helps.

I had the same issue and the only solution that worked for me was to set an alias for the gcloud command such that it gets executed by cmd.exe like so:

# in ~/.bashrc

alias gcloud="cmd.exe /c gcloud"

Then simply restart your terminal or run $ source ~/.bashrc, and the alias will take effect.

Of course, this assumes you have the gcloud CLI installed and added to your windows PATH.

Related