1. 首先到中文网下载最新的go语言环境压缩包
https://studygolang.com/dlstudygolang.com2. 然后解压缩,放置在某个地方,我存放在/usr/local/go下
3. 然后设置一下环境变量,打开.zshrc 或 .bashrc 添加
export PATH=$PATH:/usr/local/go/bin
export GOPATH=/mnt/EVA/Documents/Go # 你存放go项目的路径,之后出现不做解释
export GO111MODULE=on
export GOPROXY=https://goproxy.cn,direct # 代理加速
刷新环境后进行下一步
4. 运行如下安装gopls
go get golang.org/x/tools/gopls@latest
5. 然后运行如下
sudo cp /usr/local/go/bin/go /usr/bin/
sudo cp /usr/local/go/bin/gofmt /usr/bin/
sudo cp /mnt/EVA/Documents/Go/bin/gopls /usr/bin/
# 不知为啥我的GOPATH指定的还是/home/[user]/go, 所以我建了一个软连接到/home/[user]/go
ln -s /mnt/EVA/Documents/Go /home/[user]/go
6. 然后安装好nvim 和coc 插件,在coc-settings.json添加
"languageserver": {
"golang": {
"command": "gopls",
"rootPatterns": ["go.mod", ".vim/", ".git/", ".hg/"],
"filetypes": ["go"],
"initializationOptions": {
"usePlaceholders": true
}
},
}