golang 安装&升级
1. 下载 [https://golang.google.cn/dl/](https://golang.google.cn/dl/)
需要的golang版本
2. [tar.gz](https://dl.google.com/go/go1.13.7.darwin-amd64.tar.gz)
格式的按照说明解压(pkg格式的双击就好,不多说)
3. 解压后tar包后,mac未安装过zsh 设置环境变量vim ~/.bash_profile,
有 zsh需要vim ~/.zshrc增加
export PATH=$PATH:/Users/xxx/go/1.12.5/go/bin
export GOROOT=/Users/xxx/go/1.12.5/go
export GOPATH=/Users/xxx/go_workspace #自己的工程目录
4. source ~/.bash_profile or source ~/.zshrc
vscode环境配置:
vscode启动后会提示golang工具缺少,会自动加载GO的第三方类库,注意输出,
因为有FQ的限制,基本上无法从golang.org上下载对应的类包。每个人的情况不
一样,我的基本上都是安装失败,如下:
Installing github.com/mdempsky/gocode FAILED
Installing github.com/uudashr/gopkgs/cmd/gopkgs FAILED
Installing github.com/ramya-rao-a/go-outline FAILED
Installing github.com/acroca/go-symbols FAILED
Installing golang.org/x/tools/cmd/guru FAILED
Installing golang.org/x/tools/cmd/gorename FAILED
Installing github.com/go-delve/delve/cmd/dlv FAILED
Installing github.com/rogpeppe/godef FAILED
Installing github.com/sqs/goreturns FAILED
Installing golang.org/x/lint/golint FAILED
vscode自动安装失败,执行手动安装
第一步:
先在{$GOPATH}/src/golang.org/x目录下打开git bash,
如果没有对应的golang.org目录,自行手功创建 mkdir -p ,
执行git clone http://github.com/golang/tools。
手动安装第三方类包时,必须先安装tools类包,
必须用git来clone,否则安装其他组件如:go get -u -v github.com/cweill/gotests,
会报错package golang.org/x/tools/imports:directory"xxx/src//golang.org/x/tools/imports" is not using a known version control system错误。
第二步:
tools下载好后,
进入{$GOPATH}/src/golang.org/x/tools/cmd/gorename目录,
按shift+右键选择在此打开命令窗口,执行go install,guru也执行同样操作。
第三步:
在命令行窗口执行go get -u -v github.com/newhook/go-symbols,安装go-symbols。
其他几个同样执行此操作,包链接见下。
先在{$GOPATH}/src/github.com下执行:
git clone https://github.com/mdempsky/gocode
git clone https://github.com/uudashr/gopkgs/cmd/gopkgs
git clone https://github.com/ramya-rao-a/go-outline
git clone https://github.com/acroca/go-symbols
git clone https://golang.org/x/tools/cmd/guru
git clone https://golang.org/x/tools/cmd/gorename
git clone https://github.com/go-delve/delve/cmd/dlv
git clone https://github.com/rogpeppe/godef
git clone https://github.com/sqs/goreturns
git clone https://golang.org/x/lint/golint
之后在{$GOPATH}下执行
go install github.com/mdempsky/gocode
go install github.com/uudashr/gopkgs/cmd/gopkgs
go install github.com/ramya-rao-a/go-outline
go install github.com/acroca/go-symbols
go install golang.org/x/tools/cmd/guru
go install golang.org/x/tools/cmd/gorename
go install github.com/go-delve/delve/cmd/dlv
go install github.com/rogpeppe/godef
go install github.com/sqs/goreturns
go install golang.org/x/lint/golint
有疑问加站长微信联系(非本文作者)