侧边栏壁纸
  • 累计撰写 30 篇文章
  • 累计创建 35 个标签
  • 累计收到 4 条评论

golang 安装

GoDan
2022-04-18 / 0 评论 / 0 点赞 / 450 阅读 / 1,656 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-04-18,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

Linux 安装

wget https://studygolang.com/dl/golang/go1.18.1.linux-amd64.tar.gz
tar -zxvf go1.18.1.linux-amd64.tar.gz -C /usr/local

增加环境变量

vim /etc/profile
# 安装目录
export GOROOT=/usr/local/go
# 工作目录
export GOPATH=/data/app/godan/go
# 环境变量
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
:wq
# 重新加载
source /etc/profile

创建工作环境

# 存放项目源文件
mkdir -p /data/app/godan/go/src
# 存放编译后的包文件
mkdir -p /data/app/godan/go/pkg
# 存放编译后的可执行文件
mkdir -p /data/app/godan/go/bin

测试

查看版本与安装版本匹配

[root@ops-01 /usr/local/go]# go version
go version go1.18.1 linux/amd64

编译运行

go run hello.go

编译

go build hello.go

报错

/usr/local/go/src/runtime/internal/sys/consts.go:13:7: StackGuardMultiplier redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:27:7: other declaration of StackGuardMultiplier
/usr/local/go/src/runtime/internal/sys/consts.go:16:7: DefaultPhysPageSize redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:36:7: other declaration of DefaultPhysPageSize
/usr/local/go/src/runtime/internal/sys/consts.go:20:7: PCQuantum redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:40:7: other declaration of PCQuantum
/usr/local/go/src/runtime/internal/sys/consts.go:23:7: Int64Align redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:43:7: other declaration of Int64Align
/usr/local/go/src/runtime/internal/sys/consts.go:30:7: MinFrameSize redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:50:7: other declaration of MinFrameSize
/usr/local/go/src/runtime/internal/sys/consts.go:34:7: StackAlign redeclared in this block
/usr/local/go/src/runtime/internal/sys/arch.go:54:7: other declaration of StackAlign

重新解压安装

go.mod file not found in current directory or any parent directory; see 'go help modules

在新建项目后,要在当前文件夹执行

go mod init 项目名
0

评论区