golang环境安装问题集锦

有梦想的程序丶猿 · · 914 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

直入主题,环境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版本构建,走了好多弯路,之前不停的切换分支修改环境变量,后来突然想通,需要同时拥有两个版本。


有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:有梦想的程序丶猿

查看原文:golang环境安装问题集锦

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

914 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传