Golang最新稳定版本的URL

Is there is a permanent URL that points to current latest linux binary release of golang?

I am writing an ansible script which should download the latest golang release and install it. In the golang download site "https://golang.org/dl/" I could see only release specific download links.

I am wondering if there a link like "https://dl.google.com/go/latest.linux-amd64.tar.gz" available?

If not any suggestion on how to script fetching the latest golang version and install it?

Google has a Linux installer to install go on linux: https://storage.googleapis.com/golang/getgo/installer_linux

This 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.

I would suggest to defer to something like jlund/ansible-go, or copy over the parts of that role that you need.

You can generate the lastest 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

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"