centos 8.2中安装go 1.17
压缩包方式
下载解压
golang 1.17下载地址:https://gomirrors.org/dl/go/go1.17.7.linux-amd64.tar.gz
#解压到/usr/local/下
tar -zxvf go1.17.7.linux-amd64.tar.gz /usr/local/
#修改~/.bash_profile ,导出环境变量
export GOROOT=/usr/local/go
export GOPROXY=https://goproxy.io,direct
export GOPATH=/root/gopath
PATH=$PATH:$HOME/bin:$GOROOT/bin
export PATH
#修改完毕后
source ~/.bash_profile
验证:
[root@master ~]# go version
go version go1.17.7 linux/amd64
[root@master ~]# go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/gopath/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/gopath"
GOPRIVATE=""
GOPROXY="https://goproxy.io,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.7"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1432673404=/tmp/go-build -gno-record-gcc-switches"
[root@master ~]#
yum方式
这种方式,相关版本的包,存在滞后性,不推荐这种方式,
如下面在安装时,当前版本只能找到go 1.16版本的,无法安装最新版的1.17
[root@master opt]# yum search golang
Last metadata expiration check: 0:40:29 ago on Wed 09 Feb 2022 12:46:02 PM CST.
============================================================= Name Exactly Matched: golang ==============================================================
golang.x86_64 : The Go Programming Language
============================================================ Name & Summary Matched: golang =============================================================
golang-bin.x86_64 : Golang core compiler tools
golang-docs.noarch : Golang compiler docs
golang-misc.noarch : Golang compiler miscellaneous sources
golang-race.x86_64 : Golang std library with -race enabled
golang-src.noarch : Golang compiler source tree
golang-tests.noarch : Golang compiler tests for stdlib
python3-avocado-plugins-golang.noarch : Avocado plugin for execution of golang tests
================================================================= Name Matched: golang ==================================================================
compat-golang-github-chzyer-readline-devel.noarch : Pure Go implementation of GNU Readline-like library
golang-github-cpuguy83-md2man.x86_64 : Converts markdown into roff (man pages)
golang-github-prometheus.x86_64 : Prometheus monitoring system and time series database
golang-github-prometheus-alertmanager.x86_64 : Prometheus Alertmanager
golang-github-prometheus-node-exporter.x86_64 : Exporter for machine metrics
golang-gopkg-readline-1-devel.noarch : Pure Go implementation of GNU Readline-like library
golang-x-crypto-devel.noarch : Go supplementary cryptography libraries
golang-x-net-devel.noarch : Go supplementary network libraries
golang-x-sys-devel.noarch : Go packages for low-level interaction with the operating system
golang-x-text-devel.noarch : Go text processing support
================================================================ Summary Matched: golang ================================================================
go-srpm-macros.noarch : RPM macros for building Golang packages for various architectures
[root@master opt]# yum info golang.x86_64
Last metadata expiration check: 0:40:44 ago on Wed 09 Feb 2022 12:46:02 PM CST.
Available Packages
Name : golang
Version : 1.16.12
Release : 1.module_el8.5.0+1051+7eeb051e
Architecture : x86_64
Size : 688 k
Source : golang-1.16.12-1.module_el8.5.0+1051+7eeb051e.src.rpm
Repository : AppStream
Summary : The Go Programming Language
URL : http://golang.org/
License : BSD and Public Domain
Description : The Go Programming Language.
[root@master opt]# yum -y install golang.x86_64
Last metadata expiration check: 0:40:58 ago on Wed 09 Feb 2022 12:46:02 PM CST.
Dependencies resolved.
=========================================================================================================================================================
Package Architecture Version Repository Size
=========================================================================================================================================================
Installing:
golang x86_64 1.16.12-1.module_el8.5.0+1051+7eeb051e AppStream 688 k
Upgrading:
e2fsprogs x86_64 1.45.6-2.el8 BaseOS 1.0 M
e2fsprogs-libs x86_64 1.45.6-2.el8 BaseOS 233 k
keyutils-libs x86_64 1.5.10-9.el8 BaseOS 34 k
krb5-libs x86_64 1.18.2-14.el8 BaseOS 840 k
libcom_err x86_64 1.45.6-2.el8 BaseOS 49 k
libsepol x86_64 2.9-3.el8 BaseOS 340 k
libss x86_64 1.45.6-2.el8 BaseOS 54 k
openssl x86_64 1:1.1.1k-5.el8_5 BaseOS 709 k
openssl-libs x86_64 1:1.1.1k-5.el8_5 BaseOS 1.5 M
Installing dependencies:
golang-bin x86_64 1.16.12-1.module_el8.5.0+1051+7eeb051e AppStream 92 M
golang-src noarch 1.16.12-1.module_el8.5.0+1051+7eeb051e AppStream 8.2 M
keyutils-libs-devel x86_64 1.5.10-9.el8 BaseOS 48 k
krb5-devel x86_64 1.18.2-14.el8 BaseOS 560 k
libcom_err-devel x86_64 1.45.6-2.el8 BaseOS 38 k
libkadm5 x86_64 1.18.2-14.el8 BaseOS 187 k
libselinux-devel x86_64 2.9-5.el8 BaseOS 200 k
libsepol-devel x86_64 2.9-3.el8 BaseOS 87 k
libverto-devel x86_64 0.3.0-5.el8 BaseOS 18 k
openssl-devel x86_64 1:1.1.1k-5.el8_5 BaseOS 2.3 M
pcre2-devel x86_64 10.32-2.el8 BaseOS 605 k
pcre2-utf16 x86_64 10.32-2.el8 BaseOS 229 k
pcre2-utf32 x86_64 10.32-2.el8 BaseOS 220 k
Enabling module streams:
go-toolset rhel8
Transaction Summary
=========================================================================================================================================================
Install 14 Packages
Upgrade 9 Packages
Total download size: 110 M
Downloading Packages:
(1/23): golang-1.16.12-1.module_el8.5.0+1051+7eeb051e.x86_64.rpm 1.8 MB/s | 688 kB 00:00
(2/23): keyutils-libs-devel-1.5.10-9.el8.x86_64.rpm 470 kB/s | 48 kB 00:00
(3/23): krb5-devel-1.18.2-14.el8.x86_64.rpm 1.6 MB/s | 560 kB 00:00
(4/23): golang-src-1.16.12-1.module_el8.5.0+1051+7eeb051e.noarch.rpm 9.3 MB/s | 8.2 MB 00:00
(5/23): libcom_err-devel-1.45.6-2.el8.x86_64.rpm 361 kB/s | 38 kB 00:00
(6/23): libkadm5-1.18.2-14.el8.x86_64.rpm 847 kB/s | 187 kB 00:00
(7/23): libselinux-devel-2.9-5.el8.x86_64.rpm 1.0 MB/s | 200 kB 00:00
(8/23): libverto-devel-0.3.0-5.el8.x86_64.rpm 215 kB/s | 18 kB 00:00
(9/23): libsepol-devel-2.9-3.el8.x86_64.rpm 609 kB/s | 87 kB 00:00
(10/23): pcre2-devel-10.32-2.el8.x86_64.rpm 1.9 MB/s | 605 kB 00:00
(11/23): openssl-devel-1.1.1k-5.el8_5.x86_64.rpm 4.3 MB/s | 2.3 MB 00:00
(12/23): pcre2-utf16-10.32-2.el8.x86_64.rpm 1.0 MB/s | 229 kB 00:00
(13/23): pcre2-utf32-10.32-2.el8.x86_64.rpm 870 kB/s | 220 kB 00:00
(14/23): e2fsprogs-1.45.6-2.el8.x86_64.rpm 2.7 MB/s | 1.0 MB 00:00
(15/23): e2fsprogs-libs-1.45.6-2.el8.x86_64.rpm 1.2 MB/s | 233 kB 00:00
(16/23): keyutils-libs-1.5.10-9.el8.x86_64.rpm 409 kB/s | 34 kB 00:00
(17/23): libcom_err-1.45.6-2.el8.x86_64.rpm 417 kB/s | 49 kB 00:00
(18/23): krb5-libs-1.18.2-14.el8.x86_64.rpm 2.2 MB/s | 840 kB 00:00
(19/23): libsepol-2.9-3.el8.x86_64.rpm 1.3 MB/s | 340 kB 00:00
(20/23): golang-bin-1.16.12-1.module_el8.5.0+1051+7eeb051e.x86_64.rpm 30 MB/s | 92 MB 00:03
(21/23): libss-1.45.6-2.el8.x86_64.rpm 111 kB/s | 54 kB 00:00
(22/23): openssl-1.1.1k-5.el8_5.x86_64.rpm 1.6 MB/s | 709 kB 00:00
(23/23): openssl-libs-1.1.1k-5.el8_5.x86_64.rpm 3.7 MB/s | 1.5 MB 00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------
Total 32 MB/s | 110 MB 00:03
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Running scriptlet: golang-1.16.12-1.module_el8.5.0+1051+7eeb051e.x86_64 1/1
Preparing : 1/1
Upgrading : libcom_err-1.45.6-2.el8.x86_64 1/32
Running scriptlet: libcom_err-1.45.6-2.el8.x86_64 1/32
Upgrading : openssl-libs-1:1.1.1k-5.el8_5.x86_64 2/32
Running scriptlet: openssl-libs-1:1.1.1k-5.el8_5.x86_64 2/32
Upgrading : keyutils-libs-1.5.10-9.el8.x86_64 3/32
Upgrading : krb5-libs-1.18.2-14.el8.x86_64 4/32
Installing : libkadm5-1.18.2-14.el8.x86_64 5/32
Installing : keyutils-libs-devel-1.5.10-9.el8.x86_64 6/32
Installing : libcom_err-devel-1.45.6-2.el8.x86_64 7/32
Upgrading : e2fsprogs-libs-1.45.6-2.el8.x86_64 8/32
Running scriptlet: e2fsprogs-libs-1.45.6-2.el8.x86_64 8/32
Upgrading : libss-1.45.6-2.el8.x86_64 9/32
Running scriptlet: libss-1.45.6-2.el8.x86_64 9/32
Upgraded:
e2fsprogs-1.45.6-2.el8.x86_64 e2fsprogs-libs-1.45.6-2.el8.x86_64 keyutils-libs-1.5.10-9.el8.x86_64 krb5-libs-1.18.2-14.el8.x86_64
libcom_err-1.45.6-2.el8.x86_64 libsepol-2.9-3.el8.x86_64 libss-1.45.6-2.el8.x86_64 openssl-1:1.1.1k-5.el8_5.x86_64
openssl-libs-1:1.1.1k-5.el8_5.x86_64
Installed:
golang-1.16.12-1.module_el8.5.0+1051+7eeb051e.x86_64 golang-bin-1.16.12-1.module_el8.5.0+1051+7eeb051e.x86_64
golang-src-1.16.12-1.module_el8.5.0+1051+7eeb051e.noarch keyutils-libs-devel-1.5.10-9.el8.x86_64
krb5-devel-1.18.2-14.el8.x86_64 libcom_err-devel-1.45.6-2.el8.x86_64
libkadm5-1.18.2-14.el8.x86_64 libselinux-devel-2.9-5.el8.x86_64
libsepol-devel-2.9-3.el8.x86_64 libverto-devel-0.3.0-5.el8.x86_64
openssl-devel-1:1.1.1k-5.el8_5.x86_64 pcre2-devel-10.32-2.el8.x86_64
pcre2-utf16-10.32-2.el8.x86_64 pcre2-utf32-10.32-2.el8.x86_64
Complete!
同样,可需要导出环境变量:GOPATH、GOPROXY和GOROOT,可以选择导出到/etc/profile中,或者~/.bash_profile中。