golang环境安装问题集锦

直入主题,环境Mac os Mojave 10.14.6

配置环境变量
export GOROOT=$HOME/Development/go
export GOPATH=$HOME/Development/path 
export PATH=$PATH:$HOME/Development/go/bin:/$HOME/Development/path/bin
#建议直接设置为go1.4,后续会创建go1.4目录,由于之前编译一直设置的go,走了很多弯路。
export GOROOT_BOOTSTRAP=$HOME/Development/go1.4
编译
git clone https://github.com/golang/go.git 
cd go/src
./all.bash

报错如下

Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.
根据github提示执行
#从源代码构建Go1.4
git checkout -b 1.4.3 go1.4.3
cd src
./all.bash
#复制~/go到$GOROOT_BOOTSTRAP(~/go1.4默认情况下)`
cp ~/go ~/go1.4 -rf
#从源代码构建Go1.6
cd ~/go
git clean -dfx
git checkout -b 1.6 go1.6
cd src
./all.bash

报错如下

missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
安装
xcode-select --install
再次编译
./all.bash

报错如下

Building Go cmd/dist using /Users/zhangzhichao/Development/go1.4.
Building Go toolchain1 using /Users/zhangzhichao/Development/go1.4.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
/Users/zhangzhichao/Development/go/src/runtime/zruntime_defs_darwin_amd64.go:7:7: _Gidle redeclared in this block
    previous declaration at /Users/zhangzhichao/Development/go/src/runtime/runtime2.go:35:11
/Users/zhangzhichao/Development/go/src/runtime/zruntime_defs_darwin_amd64.go:8:7: _Grunnable redeclared in this block
    previous declaration at /Users/zhangzhichao/Development/go/src/runtime/runtime2.go:39:2
/Users/zhangzhichao/Development/go/src/runtime/zruntime_defs_darwin_amd64.go:9:7: _Grunning redeclared in this block
    previous declaration at /Users/zhangzhichao/Development/go/src/runtime/runtime2.go:44:2
/Users/zhangzhichao/Development/go/src/runtime/zruntime_defs_darwin_amd64.go:10:7: _Gsyscall redeclared in this block
    previous declaration at /Users/zhangzhichao/Development/go/src/runtime/runtime2.go:49:2
/Users/zhangzhichao/Development/go/src/runtime/zruntime_defs_darwin_amd64.go:11:7: _Gwaiting redeclared in this block
再次编译
git clean -df

最终编译完成

##### ../misc/cgo/testcshared
SKIP - short mode and $GO_BUILDER_NAME not set

##### ../misc/cgo/testplugin
ok      misc/cgo/testplugin 0.008s

##### ../misc/cgo/errors
PASS

##### ../test/bench/go1

##### ../test

##### API check
Go version is "go1.13rc1", ignoring -next /Users/zhangzhichao/Development/go/api/next.txt

ALL TESTS PASSED
---
Installed Go for darwin/amd64 in /Users/zhangzhichao/Development/go
Installed commands in /Users/zhangzhichao/Development/go/bin

go新版本会依赖go1.4版本构建,走了好多弯路,之前不停的切换分支修改环境变量,后来突然想通,需要同时拥有两个版本。

推荐阅读更多精彩内容