Ubuntu 16.04下安装golang

手动安装

下载golang安装包

https://studygolang.com/dl

从上面的网站上下载适合自己机器的go版本,我这里选择的是go1.10.linux-386.tar.gz

解压安装包到指定目录

sudo tar -zxvf go1.10.linux-386.tar.gz -C /opt

检查是否安装成功

./opt/go/bin/go version

环境变量的设置

vi /etc/profile

export GOPATH=/home/go
export GOROOT=/opt/go
export GOARCH=386
export GOOS=linux
export GOTOOLS=$GOROOT/pkg/tool
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

source /etc/profile

编写hello.go文件,测试安装是否成功

package main
import "fmt"
func main(){
	fmt.Println("hello,world!")
}

用go run命令直接运行hello.go

go run hello.go

用go build命令生成hello可执行文件

go build hello.go 
posted @ 2018-04-10 10:59  木易森林  阅读(7833)  评论(1编辑  收藏  举报