在Ubuntu上安装最新版本的Go语言

首先

在Ubuntu上使用apt安装Go语言时,可能会安装一个略旧的版本,为了安装最新的版本,我们需要进行一些调整。

环境

Ubuntu 20.04.3 长期支持版

安装Go语言

执行以下命令,Go的版本为1.13,APT的源指向Ubuntu的网站。

$ apt info golang
Package: golang
Version: 2:1.13~1ubuntu2
Priority: optional
Section: devel
Source: golang-defaults
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Go Compiler Team <team+go-compiler@tracker.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 12.3 kB
Depends: golang-1.13, golang-doc (>= 2:1.13~1ubuntu2), golang-go (>= 2:1.13~1ubuntu2), golang-src (>= 2:1.13~1ubuntu2)
Homepage: https://golang.org
Download-Size: 2,900 B
APT-Sources: http://jp.archive.ubuntu.com/ubuntu focal/main amd64 Packages
Description: Go programming language compiler - metapackage
 The Go programming language is an open source project to make
 programmers more productive. Go is expressive, concise, clean, and
 efficient. Its concurrency mechanisms make it easy to write programs
 that get the most out of multicore and networked machines, while its
 novel type system enables flexible and modular program construction.
 Go compiles quickly to machine code yet has the convenience of
 garbage collection and the power of run-time reflection. It's a
 fast, statically typed, compiled language that feels like a
 dynamically typed, interpreted language.
 .
 This package is a metapackage that, when installed, guarantees
 that (most of) a full Go development environment is installed.

在APT源中添加PPA。

$ sudo add-apt-repository ppa:longsleep/golang-backports
$ sudo apt update

当再次检查软件包时,我们发现APT源和语言版本已经更新。

$ apt info golang
Package: golang
Version: 2:1.17~1longsleep1
Priority: optional
Section: devel
Source: golang-defaults
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Go Compiler Team <team+go-compiler@tracker.debian.org>
Installed-Size: 12.3 kB
Depends: golang-1.17, golang-doc (>= 2:1.17~1longsleep1), golang-go (>= 2:1.17~1longsleep1), golang-src (>= 2:1.17~1longsleep1)
Download-Size: 5,008 B
APT-Sources: http://ppa.launchpad.net/longsleep/golang-backports/ubuntu focal/main amd64 Packages
Description: Go programming language compiler - metapackage
 The Go programming language is an open source project to make
 programmers more productive. Go is expressive, concise, clean, and
 efficient. Its concurrency mechanisms make it easy to write programs
 that get the most out of multicore and networked machines, while its
 novel type system enables flexible and modular program construction.
 Go compiles quickly to machine code yet has the convenience of
 garbage collection and the power of run-time reflection. It's a
 fast, statically typed, compiled language that feels like a
 dynamically typed, interpreted language.
 .
 This package is a metapackage that, when installed, guarantees
 that (most of) a full Go development environment is installed.

安装Go。

$ sudo apt install golang

已安装版本为1.17。

$ go version
go version go1.17.5 linux/amd64

请参阅

广告
将在 10 秒后关闭
bannerAds