mac本机最早是brew install的go 1.3.3版本,今年1月份通过brew upgrade到1.4版本。
但是brew的官方更新实在太慢了,等不及,手动升级到1.5.1版本。
1.从官网 https://golang.org/dl/ 下载 go1.5.1.darwin-amd64.tar.gz
cd /Users/wenke/Documents/tools/go
mv /Users/wenke/Downloads/go1.5.1.darwin-amd64.tar.gz ./
tar zxvf go1.5.1.darwin-amd64.tar.gz
xattr -r -c go
mv go 1.5.1
2.修改liteIDE的配置文件:
GOROOT=/usr/local/Cellar/go/1.4/libexec
变成:
GOROOT=/Users/wenke/Documents/tools/go/1.5.1
3.修改硬链接文件
go version
go version go1.4 darwin/amd64
which go
/usr/local/bin/go
cd /usr/local/bin
ll go*
lrwxr-xr-x 1 root admin 23 1 11 2015 go -> ../Cellar/go/1.4/bin/go
lrwxr-xr-x 1 root admin 26 1 11 2015 gofmt -> ../Cellar/go/1.4/bin/gofmt
rm go
sudo ln -s /Users/wenke/Documents/tools/go/1.5.1/bin/go go
rm gofmt
sudo ln -s /Users/wenke/Documents/tools/go/1.5.1/bin/gofmt gofmt
ll go*
lrwxr-xr-x 1 root admin 44 11 20 13:50 go -> /Users/wenke/Documents/tools/go/1.5.1/bin/go
lrwxr-xr-x 1 root admin 44 11 20 13:50 gofmt -> /Users/wenke/Documents/tools/go/1.5.1/bin/gofmt
go version
go version go1.5.1 darwin/amd64
4.修改环境变量
vi ~/.zshrc
export GOROOT=/Users/wenke/Documents/tools/go/1.5.1
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOROOT/bin
export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin
source .zshrc
5.删除旧版本编译生成的文件
rm -rf $GOPATH/pkg
Tip:
如果升级完之后,编译或者运行旧项目报错:
go build
package ysz
imports runtime: C source files not allowed when not using cgo or SWIG: atomic_amd64x.c defs.c float.c heapdump.c lfstack.c malloc.c mcache.c mcentral.c mem_darwin.c mfixalloc.c mgc0.c mheap.c msize.c os_darwin.c panic.c parfor.c proc.c runtime.c signal.c signal_amd64x.c signal_unix.c stack.c string.c sys_x86.c
这是环境变量没有生效的原因。只需要source .zshrc 或者新开终端就可以解决!
但是brew的官方更新实在太慢了,等不及,手动升级到1.5.1版本。
1.从官网 https://golang.org/dl/ 下载 go1.5.1.darwin-amd64.tar.gz
cd /Users/wenke/Documents/tools/go
mv /Users/wenke/Downloads/go1.5.1.darwin-amd64.tar.gz ./
tar zxvf go1.5.1.darwin-amd64.tar.gz
xattr -r -c go
mv go 1.5.1
2.修改liteIDE的配置文件:
GOROOT=/usr/local/Cellar/go/1.4/libexec
变成:
GOROOT=/Users/wenke/Documents/tools/go/1.5.1
3.修改硬链接文件
go version
go version go1.4 darwin/amd64
which go
/usr/local/bin/go
cd /usr/local/bin
ll go*
lrwxr-xr-x 1 root admin 23 1 11 2015 go -> ../Cellar/go/1.4/bin/go
lrwxr-xr-x 1 root admin 26 1 11 2015 gofmt -> ../Cellar/go/1.4/bin/gofmt
rm go
sudo ln -s /Users/wenke/Documents/tools/go/1.5.1/bin/go go
rm gofmt
sudo ln -s /Users/wenke/Documents/tools/go/1.5.1/bin/gofmt gofmt
ll go*
lrwxr-xr-x 1 root admin 44 11 20 13:50 go -> /Users/wenke/Documents/tools/go/1.5.1/bin/go
lrwxr-xr-x 1 root admin 44 11 20 13:50 gofmt -> /Users/wenke/Documents/tools/go/1.5.1/bin/gofmt
go version
go version go1.5.1 darwin/amd64
4.修改环境变量
vi ~/.zshrc
export GOROOT=/Users/wenke/Documents/tools/go/1.5.1
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOROOT/bin
export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin
source .zshrc
5.删除旧版本编译生成的文件
rm -rf $GOPATH/pkg
Tip:
如果升级完之后,编译或者运行旧项目报错:
go build
package ysz
imports runtime: C source files not allowed when not using cgo or SWIG: atomic_amd64x.c defs.c float.c heapdump.c lfstack.c malloc.c mcache.c mcentral.c mem_darwin.c mfixalloc.c mgc0.c mheap.c msize.c os_darwin.c panic.c parfor.c proc.c runtime.c signal.c signal_amd64x.c signal_unix.c stack.c string.c sys_x86.c
这是环境变量没有生效的原因。只需要source .zshrc 或者新开终端就可以解决!
有疑问加站长微信联系(非本文作者)