Skip to content

Instantly share code, notes, and snippets.

@oofnikj
Last active August 12, 2025 11:18
Show Gist options
  • Select an option

  • Save oofnikj/7a2fb1e6b20b397775d882ecd8980159 to your computer and use it in GitHub Desktop.

Select an option

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
@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