Linux下安装go

Posted by 聪少 on 2019-05-24

下载

国内下载地址

解压

1
tar -zxf goVersion.linux-amd64.tar.gz -C /usr/local/

创建工作空间(GOPATH)

1
mkdir /root/gowork

设置环境变量

1
2
3
4
5
6
7
8
vim /etc/profile
export GOROOT=/usr/local/go
export GOBIN=$GOROOT/bin
export GOPKG=$GOROOT/pkg/tool/linux_amd64
export GOARCH=amd64
export GOOS=linux
export GOPATH=/root/gowork
export PATH=$PATH:$GOBIN:$GOPKG:$GOPATH/bin

重载配置

1
source /etc/profile

使之生效,或者重新登录Linux也可

测试

创建文件

1
2
3
4
5
6
7
package main

import "fmt"

func main() {
fmt.Println("Hello, World!")
}
1
2
go run test.go
Hello, World!