报错信息如下
# internal/unsafeheader
compile: version "go1.16" does not match go tool version "go1.16.3"
# unicode/utf8
compile: version "go1.16" does not match go tool version "go1.16.3"
原因分析
我们在系统中 有多个 go 环境造成的;
- 如果是通过 brew install go 的方式安装的 go环境【1.16.3】;
那么,go的环境会默认安装在路径如下 /usr/local/Cellar
jason@local bin$ ls -la /usr/local/bin/go*
lrwxr-xr-x 1 jason admin 26 9 15 16:10 go -> ../Cellar/go/1.16.3/bin/go
lrwxr-xr-x 1 jason admin 39 3 27 20:14 gobject-query -> ../Cellar/glib/2.66.7/bin/gobject-query
lrwxr-xr-x 1 jason admin 29 9 15 16:10 gofmt -> ../Cellar/go/1.16.3/bin/gofmt
这就成就了 go1.16.3 的环境
- 如果是通过下载安装包的方式安装的 go 环境【1.16】;
那么,go的默认安装路径如下 /usr/local/go
jason@local bin$ ls /usr/local/go
AUTHORS CONTRIBUTORS PATENTS SECURITY.md api doc lib pkg src
CONTRIBUTING.md LICENSE README.md VERSION bin favicon.ico misc robots.txt test
- 而我们系统PATH中配置 go的环境假设在 /usr/local/bin 下
jason@local bin$ ls -la /usr/local/bin/go*
lrwxr-xr-x 1 jason admin 26 9 15 16:10 go -> ../Cellar/go/1.16.3/bin/go
lrwxr-xr-x 1 jason admin 39 3 27 20:14 gobject-query -> ../Cellar/glib/2.66.7/bin/gobject-query
lrwxr-xr-x 1 jason admin 29 9 15 16:10 gofmt -> ../Cellar/go/1.16.3/bin/gofmt
- 系统再编译go的时候,系统调用的应该是【 /usr/local/go/bin 下面的 1.16 环境】,go tool 中使用的 应该是 【/usr/local/bin 下面的 1.16.3环境】
解决方案
- 卸载 1.16.3 的 go
jason@local bin$ brew uninstall go
Error: Refusing to uninstall /usr/local/Cellar/go/1.16.3
because it is required by glide, which is currently installed.
You can override this and force removal with:
brew uninstall --ignore-dependencies go
jason@local bin$ brew uninstall --ignore-dependencies go
Uninstalling /usr/local/Cellar/go/1.16.3... (9,955 files, 503.5MB)
- 手动建立软连接(/usr/local/bin 目录下)
jason@local bin$ cd /usr/local/bin
jason@local bin$ ln -s /usr/local/go/bin/go ./go
jason@local bin$ ln -s /usr/local/go/bin/gofmt ./gofmt