linux系统 go 语言安装

1,下载

https://golang.google.cn/dl/

wget https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz

2.解压安装

https://golang.google.cn/doc/install

 tar -C /usr/local -xzf go1.13.5.linux-amd64.tar.gz

3.添加环境变量

export PATH=$PATH:/usr/local/go/bin #重启系统会消失

配置所有用户
所以需添加到用户/etc/profile文件末

 

 

  执行 source /etc/profile

 GOROOT为go安装目录

 GOPATH为工作目录 如 go get 下载的文件会放到该目录下,

 GOOBIN为生成文件可运行目录

只配置当前用户

export GOROOT=/usr/local/go
export GOPATH=~/goproject
export GOBIN=~/gobin
export PATH=$PATH:$GOROOT/bin:$GOBIN

将上边内容加入~/.profile
我的测试机centos7加入到文件末 /root/.bash_profile 

source   /root/.bash_profile 

4.测试

go version 显示版本信息
go version go1.13.5 linux/amd64

创建  hello.go 

cd ~/goproject

 vi hello.go

package main

import "fmt"

func main() {
	fmt.Printf("hello, world\n")
}

 go build hello.go 

 

 

 

 测试成功

 5.Go 模块代理设置,解决国外网站模块下载慢或不能下载问题

linux下

echo "export GOPROXY=https://goproxy.cn" >> ~/.bash_profile && source ~/.bash_profile

 go env -w GOPROXY=https://goproxy.cn,direct

windows

 打开你的 PowerShell 并执行:

C:\> $env:GOPROXY = "https://goproxy.cn"

 参考文档

https://golang.google.cn/doc/install

https://github.com/goproxy/goproxy.cn/blob/master/README.md




posted @ 2020-01-04 15:12  不经一番寒彻骨  阅读(1432)  评论(0编辑  收藏  举报