介绍
Go是一种由Google支持的开源编程语言,易于学习和入门,内置并发性和健壮的标准库,有不断增长的合作伙伴、社区和工具生态系统
查找
运行dnf info 查看,系统软件仓库中已经存在,但是版本为1.16,有的软件需要安装go 1.18,那需要从官网下载安装包安装
[root@iZ2zee2m456rb6bde98jpkZ ~]# dnf info golang
Last metadata expiration check: 0:13:41 ago on Wed 29 Jun 2022 10:47:19 AM CST.
Available Packages
Name : golang
Version : 1.16.12
Release : 1.al8
Architecture : x86_64
Size : 688 k
Source : golang-1.16.12-1.al8.src.rpm
Repository : alinux3-updates
Summary : The Go Programming Language
URL : http://golang.org/
License : BSD and Public Domain
Description : The Go Programming Language.
打开https://golang.google.cn/dl 找到linux版本下载路径,用wget下载
[root@iZ2zee2m456rb6bde98jpkZ ~]# wget -c https://golang.google.cn/dl/go1.18.3.linux-amd64.tar.gz
--2022-06-29 11:04:44-- https://golang.google.cn/dl/go1.18.3.linux-amd64.tar.gz
Resolving golang.google.cn (golang.google.cn)... 220.181.174.162
Connecting to golang.google.cn (golang.google.cn)|220.181.174.162|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://dl.google.com/go/go1.18.3.linux-amd64.tar.gz [following]
--2022-06-29 11:04:44-- https://dl.google.com/go/go1.18.3.linux-amd64.tar.gz
Resolving dl.google.com (dl.google.com)... 220.181.174.225
Connecting to dl.google.com (dl.google.com)|220.181.174.225|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 141748419 (135M) [application/x-gzip]
Saving to: ‘go1.18.3.linux-amd64.tar.gz’
go1.18.3.linux-amd64.tar.gz 100%[=================================================================================>] 135.18M 11.6MB/s in 11s
2022-06-29 11:04:55 (12.7 MB/s) - ‘go1.18.3.linux-amd64.tar.gz’ saved [141748419/141748419]
安装
解压压缩包,安装到/usr/local目录,然后配置PATH变量到.bashrc,并引入当前环境,使用go version查看版本
[root@iZ2zee2m456rb6bde98jpkZ ~]# tar zxf go1.18.3.linux-amd64.tar.gz -C /usr/local/
[root@iZ2zee2m456rb6bde98jpkZ ~]# echo "export PATH=/usr/local/go/bin:$PATH" >> .bashrc
[root@iZ2zee2m456rb6bde98jpkZ ~]# source .bashrc
[root@iZ2zee2m456rb6bde98jpkZ ~]# go version
go version go1.18.3 linux/amd64
配置软件包代理
[root@iZ2zee2m456rb6bde98jpkZ ~]# echo "export GOPROXY=https://proxy.golang.com.cn,direct" >> .bashrc
[root@iZ2zee2m456rb6bde98jpkZ ~]# source .bashrc
[root@iZ2zee2m456rb6bde98jpkZ ~]# go env |grep GOPROXY
GOPROXY="https://proxy.golang.com.cn,direct"
运行
新建目录test1,用vi main.go编辑文件
package main
import "fmt"
func main() {
fmt.Println("golang install test")
}
go run main.go 运行
[root@iZ2zee2m456rb6bde98jpkZ test1]# go run main.go
golang install test