【问题标题】:URL for golang latest stable releasegolang 最新稳定版本的 URL
【发布时间】:2019-08-30 18:50:48
【问题描述】:

是否有指向当前最新的 linux 二进制 golang 版本的永久 URL?

我正在编写一个 ansible 脚本,它应该下载最新的 golang 版本并安装它。在 golang 下载站点“https://golang.org/dl/”中,我只能看到发布特定的下载链接。

我想知道是否有类似“https://dl.google.com/go/latest.linux-amd64.tar.gz”的链接可用?

如果没有关于如何编写脚本获取最新的 golang 版本并安装它的建议?

【问题讨论】:

    标签: go


    【解决方案1】:

    您可以一次性下载最新的稳定版 GO :)

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

    【讨论】:

    • wget "https://dl.google.com/go/$(curl 'https://golang.org/VERSION?m=text').linux-amd64.tar.gz" 有用
    • 这个方法已经不行了。 URL 已更改。 https://go.dev/dl/<VERSION> 并用于获取版本 https://go.dev/VERSION?m=text
    • @Shabirmean /VERSION?m=text url 不适合使用——它返回支持 go.dev 网站的 go 版本,现在是 1.18.1,流血尚未提供下载的边缘版本!您真正要使用的 URL 是https://go.dev/dl/?mode=json。详情请见github.com/golang/go/issues/51135
    【解决方案2】:

    您可以使用 :

    生成最新的 url
    https://dl.google.com/go{{ version }}.{{ os }}-{{ arch }}.tar.gz
    

    操作系统:linux、darwin、windows、freebsd 拱:amd64、386、armv6l、arm64、s390、ppc64le

    对于最新的稳定版本,您可以使用 curl 或其他内容从 url 获取值:

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

    这里有一个 ansible playbook 作为示例:

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

    【讨论】:

    • 我认为您误解了这个问题。他们不想要最新版本 number,他们想要最新版本 installer
    • 你是对的,只是 url https://golang.org/VERSION?m=text 是不够的,但这是另一个答案中缺少的部分来制作脚本,我已经更新了我的答案以更完整。
    【解决方案3】:

    Google 有一个 Linux 安装程序可以在 linux 上安装 go: https://storage.googleapis.com/golang/getgo/installer_linux

    这会获取最新版本的“go”并安装它。似乎这是目前在 Linux 上安装最新版本的最简单方法。

    【讨论】:

      【解决方案4】:

      我建议遵循jlund/ansible-go 之类的内容,或者复制该角色中您需要的部分。

      【讨论】:

      • 似乎这个角色需要在“go_version_target”变量中指定“go”版本。它不仅会获取最新的“go”版本。
      • 引用包描述:“安装Go的Ansible角色(golang.org)。默认安装为x86 64位Linux系统编译的最新稳定版本,不同平台和版本通过修改角色变量来支持。”这与源代码不一致吗?
      • 在“ansible-go/defaults/main.yml”中,默认版本指向“go1.8.1.linux-amd64.tar.gz”。目前最新版本是 go1.10.3.linux-amd64.tar.gz 默认版本是一年前更新的。实际上,还需要手动更新此软件包中的最新版本!!!
      猜你喜欢
      • 2017-04-10
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多