1.配置apt源
vim /etc/apt/sources.list
然后复制以下内容,当然为了保险起见可以先备份原文件
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
2.安装golang
sudo apt-get install golang
3.设置gopath , 用于放置第三方lib库文件
1.临时修改:export GOPATH=/opt/go
2.直接修改 ~/.bashrc
echo export GOPATH=/opt/go >> ~/.bashrc
3.编写第一个go程序
package main
import "fmt"
func main() {
fmt.Println("Hello world!")
}
4.运行go build
go build main.go
./main
有疑问加站长微信联系(非本文作者)