以 go1.17.2为例

安装go

  1. 下载源码包:wget https://dl.google.com/go/go1.17.2.linux-amd64.tar.gz
  2. 在/usr/local下解压源码包:sudo tar -zxf go1.17.2.linux-amd64.tar.gz -C /usr/local

    配置环境变量

    由于我使用的shell是 zsh,就以 zsh 为例:

  3. 进入 zsh 配置文件:vi ~/.zshrc

  4. 添加字段:

export GOROOT=/usr/local/go
export GOPATH=~/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

  1. 执行配置文件脚本:source ~/.zshrc

    配置代理

    env -w GOPROXY=https://goproxy.cn,direct

    vscode 配置

  2. 安装 vscode go 插件;

  3. 安装 go tools,建议直接使用 go get,使用的 tools 列表如下:
    1. go get -u -v github.com/ramya-rao-a/go-outline
    2. go get -u -v github.com/acroca/go-symbols
    3. go get -u -v github.com/mdempsky/gocode
    4. go get -u -v github.com/rogpeppe/godef
    5. go get -u -v golang.org/x/tools/cmd/godoc
    6. go get -u -v github.com/zmb3/gogetdoc
    7. go get -u -v golang.org/x/lint/golint
    8. go get -u -v github.com/fatih/gomodifytags
    9. go get -u -v golang.org/x/tools/cmd/gorename
    10. go get -u -v sourcegraph.com/sqs/goreturns
    11. go get -u -v golang.org/x/tools/cmd/goimports
    12. go get -u -v github.com/cweill/gotests/...
    13. go get -u -v golang.org/x/tools/cmd/guru
    14. go get -u -v github.com/josharian/impl
    15. go get -u -v github.com/haya14busa/goplay/cmd/goplay
    16. go get -u -v github.com/uudashr/gopkgs/cmd/gopkgs
    17. go get -u -v github.com/davidrjenni/reftools/cmd/fillstruct

可以开始愉快的写 go 程序了。