Go 1.22 安装使用

JC39
JC39
Published on 2024-11-08 / 191 Visits
0
0

安装

# 获取资源
export tmp_go_tar=go1.22.2.linux-amd64.tar.gz
wget https://go.dev/dl/${tmp_go_tar}
tar -zxf ${tmp_go_tar} && rm -f ${tmp_go_tar}
mv go/ /usr/local/

# 配置环境, EOF 用单引号括起来时, 里面的 shell 变量不会展开
sudo tee /etc/profile.d/golang_env.sh > /dev/null << 'EOF'
export GOROOT=/usr/local/go
export GOPATH=${HOME}/go
export PATH=${GOROOT}/bin:${GOPATH}/bin:${PATH}
EOF
. /etc/profile

# 查看版本
go version

# 设置代理
go env -w GOPROXY=https://goproxy.cn,direct

常用

# 初始化模块
go mod init <module-name>

# 移除未使用依赖
go mod tidy

# 安装依赖模块
go get <module-name>

# 编译, 指定输出名称
go build -o <output-name>
go build -o <output-name> <src-path> # 指定源代码位置

其他

NULL


Comment