Skip to content

Instantly share code, notes, and snippets.

@oofnikj
Last active August 12, 2025 11:18
Show Gist options
  • Save oofnikj/7a2fb1e6b20b397775d882ecd8980159 to your computer and use it in GitHub Desktop.
Save oofnikj/7a2fb1e6b20b397775d882ecd8980159 to your computer and use it in GitHub Desktop.
Download and install latest google-cloud-sdk on Alpine / Debian / Ubuntu
#!/bin/sh -e
######
# Tested with various flavors of Alpine, Ubuntu and Debian. CentOS / RedHat not supported (yet).
# Use:
# wget -qO- https://gist.githubusercontent.com/oofnikj/7a2fb1e6b20b397775d882ecd8980159/raw | sh
######
SDK_DIR=/usr/local/lib
which apt && apt update && apt install -y wget jq python3 ca-certificates --no-install-recommends || true
which apk && apk update && apk add wget jq python3 ca-certificates || true
wget -qO- \
"https://www.googleapis.com/storage/v1/b/cloud-sdk-release/o?prefix=google-cloud-sdk-2" \
| jq -r '.items[].selfLink | select ( match ("linux-x86_64") )' \
| tail -n1 \
| wget -qO- $(awk '{print $1"?alt=media"}') | tar xzf - -C $SDK_DIR
/usr/local/lib/google-cloud-sdk/install.sh --quiet
echo "export PATH=$SDK_DIR/google-cloud-sdk/bin:$PATH" | tee -a /etc/profile.d/gcloud-sdk.sh
. /etc/profile
gcloud version
@sukhwinder1011git
Copy link

Traceback (most recent call last):
File "/usr/local/lib/google-cloud-sdk/bin/bootstrapping/install.py", line 12, in
import bootstrapping
File "/usr/local/lib/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 46, in
from googlecloudsdk.core.updater import update_manager
File "/usr/local/lib/google-cloud-sdk/lib/googlecloudsdk/core/updater/update_manager.py", line 39, in
from googlecloudsdk.core.console import progress_tracker
File "/usr/local/lib/google-cloud-sdk/lib/googlecloudsdk/core/console/progress_tracker.py", line 631, in
class _BaseStagedProgressTracker(collections.Mapping):
^^^^^^^^^^^^^^^^^^^
AttributeError: module 'collections' has no attribute 'Mapping'

@Appelpitje
Copy link

Traceback (most recent call last): File "/usr/local/lib/google-cloud-sdk/bin/bootstrapping/install.py", line 12, in import bootstrapping File "/usr/local/lib/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 46, in from googlecloudsdk.core.updater import update_manager File "/usr/local/lib/google-cloud-sdk/lib/googlecloudsdk/core/updater/update_manager.py", line 39, in from googlecloudsdk.core.console import progress_tracker File "/usr/local/lib/google-cloud-sdk/lib/googlecloudsdk/core/console/progress_tracker.py", line 631, in class _BaseStagedProgressTracker(collections.Mapping): ^^^^^^^^^^^^^^^^^^^ AttributeError: module 'collections' has no attribute 'Mapping'

Had the same issue, you need to use python 3.9 or lower

@rosmo
Copy link

rosmo commented Aug 12, 2025

Here's the one I used as of today:

ARG TARGETARCH
ARG TARGETOS
RUN if [ "$TARGETARCH" = "amd64" ] ; then \
    GCLOUD_ARCH="${TARGETOS}-x86_64"; \
    elif [ "$TARGETARCH" = "arm64" ] ; then \
    GCLOUD_ARCH="${TARGETOS}-arm"; \
    fi; \
    export GCLOUD_ARCH; \
    env | grep GCLOUD_ARCH >> /etc/profile.d/gcloud-arch.env
RUN . /etc/profile.d/gcloud-arch.env
RUN curl -sL \
    "https://www.googleapis.com/storage/v1/b/cloud-sdk-release/o?prefix=google-cloud-sdk-5" \
    | jq -r ".items[].selfLink | select ( match (\"${GCLOUD_ARCH}\") )" \
    | grep '.tar.gz' \
    | tail -n1 \
    | curl -sL $(awk '{print $1"?alt=media"}') | tar xzf - -C $SDK_DIR
RUN /usr/local/lib/google-cloud-sdk/install.sh --quiet
RUN echo "export PATH=$SDK_DIR/google-cloud-sdk/bin:$PATH" | tee -a /etc/profile.d/gcloud-sdk.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment