0.环境 ubuntuUbuntu 16.04.5 LTS
1.go语言安装
1.1 安装
sudo apt-get install golang-go
1.2. 设置Go环境变量
打开终端,输入命令:
export GOROOT=$HOME/go
export PATH=$GOROOT/bin:$PATHU
1.3. 设置go代码目录
sudo mkdir Applications/go
2.测试安装
完成安装后,新建一个文档来测试环境是否搭建成功:
helloWorld.go
package main
import (
"fmt"
"runtime"
)
func main() {
fmt.Println("Hellow World!", runtime.Version())
}
执行go run helloWorld.go, 应该会打印出:
Hellow World! %!(EXTRA string=go1.6.2)
或者go build helloWorld.go,将生成helloWorld.sh,./helloWorld也可以运行。
3.编译器golang
3.1安装gvm所需依赖
sudo apt-get install curl git mercurial make binutils bison gcc build-essential
3.2安装gvm
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
安装完成
Cloning from https://github.com/moovweb/gvm.git to /home/yyw/.gvm
Created profile for existing install of Go at "/usr/lib/go-1.6"
Installed GVM v1.0.22
Please restart your terminal session or to get started right away run
`source /home/yyw/.gvm/scripts/gvm`
3.3重启终端
上面 第5行告诉你重启终端 执行
source /home/c3t/.gvm/scripts/gvm