Is there is a permanent URL that points to current latest linux binary release of Go?
I am writing an ansible script which should download the latest Go release and install it. In the Go 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?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With