是否有指向golang当前最新linux二进制版本的永久URL?
我正在写一个ansible脚本,它应该下载最新的golang版本并安装它。在golang下载站点"https://golang.org/dl/“中,我只能看到特定版本的下载链接。
我想知道有没有像"https://dl.google.com/go/latest.linux-amd64.tar.gz“这样的链接?
如果没有,关于如何编写脚本获取最新版本的golang并安装它,有什么建议吗?
发布于 2018-08-22 21:17:24
谷歌有一个在Linux上安装go的linux安装程序:https://storage.googleapis.com/golang/getgo/installer
这将获取"go“的最新版本并安装它。到目前为止,这似乎是在Linux上安装最新go版本的最简单方法。
发布于 2019-08-30 18:50:49
你可以一次下载最新的稳定版GO :)
wget "https://dl.google.com/go/$(curl https://golang.org/VERSION?m=text).linux-amd64.tar.gz"发布于 2019-05-17 06:52:27
您可以使用以下命令生成最新的url:
https://dl.google.com/go{{ version }}.{{ os }}-{{ arch }}.tar.gz操作系统: linux,darwin,windows,freebsd arch : amd64,386,armv6l,arm64,s390,ppc64le
对于最新的稳定版本,您可以使用curl或其他命令从url获取该值:
https://golang.org/VERSION?m=text以下是一个ansible攻略作为示例:
---
- 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_prefixhttps://stackoverflow.com/questions/51933636
复制相似问题