URL for golang latest stable release

As found here, Google has a Linux installer to install Go on linux:

https://storage.googleapis.com/golang/getgo/installer_linux

This installer fetches the latest version of Go and installs it. Seems like this is the easiest way as of now to install the latest go version on Linux.

The newest official method to fetch the file and execute it is:

curl -LO https://get.golang.org/$(uname)/go_installer
chmod +x go_installer
./go_installer
rm go_installer

You can download the latest stable GO version in one go :)

wget "https://dl.google.com/go/$(curl https://golang.org/VERSION?m=text).linux-amd64.tar.gz"

You can generate the latest url with :

https://dl.google.com/go{{ version }}.{{ os }}-{{ arch }}.tar.gz

os: linux, darwin, windows, freebsd
arch: amd64, 386, armv6l, arm64, s390, ppc64le

and for the latest stable version you can fetch the value with curl or something else from the url :

https://golang.org/VERSION?m=text

Here is an ansible playbook as an example :

---
- hosts: server
  gather_facts: no

  vars:
    version : "latest"
    arch: arm64
    os: linux

    latest_version_url: https://golang.org/VERSION?m=text
    archive_name: "{{ filename_prefix }}.{{ os }}-{{ arch }}.tar.gz"
    download_url: https://dl.google.com/go/{{ archive_name }}
    bin_path: /usr/local/go/bin

  tasks:
    - name: Get filename prefix with latest version
      set_fact:
        filename_prefix: "{{ lookup('url', latest_version_url, split_lines=False) }}"
      when: version == "latest"
    
    - name: Get filename prefix with fixed version
      set_fact:
        filename_prefix: go{{ version }}
      when: version != "latest"
    
    - name: Try to get current go version installed
      command: go version
      register: result
      changed_when: false

    - name: Set current_version var to the current
      set_fact:
        current_version: "{{ result.stdout.split(' ')[2] }}"
      when: result.failed == false

    - name: Set current_version var to none
      set_fact:
        current_version: "none"
      when: result.failed == true

    - debug:
        var: current_version

    - name: Download and extract the archive {{ archive_name }}
      become: true
      unarchive:
          src: "{{ download_url }}"
          dest: /usr/local
          remote_src: yes
      when: current_version != filename_prefix

Tags:

Go