安裝golang
# 到官網下載下傳二進制包https://golang.org/dl/ 或者 https://studygolang.com/dl
# 解壓包
tar -xvf go1.12.9.linux-amd64.tar.gz
# 移動到正常目錄下
sudo mv go /usr/local/
# 添加環境變量, 配置代理, 啟用gomod
sudo vim /etc/profile.d/golang.sh
export PATH=$PATH:/usr/local/go/bin
export GO111MODULE=on
export GOPROXY=https://goproxy.io
# 加載環境變量
source /etc/profile.d/golang.sh
# 測試安裝
go version
安裝vscode
到官網下載下傳vscode
https://code.visualstudio.com/下載下傳deb包輕按兩下安裝或者dpkg -i 安裝即可
安裝vscode 的go插件
安裝其他工具
如果因為牆原因無法安裝,請翻牆,或者手動安裝
https://github.com/Microsoft/vscode-go/wiki/Go-tools-that-the-Go-extension-depends-on安裝日志
Installing github.com/mdempsky/gocode SUCCEEDED
Installing github.com/uudashr/gopkgs/cmd/gopkgs SUCCEEDED
Installing github.com/ramya-rao-a/go-outline SUCCEEDED
Installing github.com/acroca/go-symbols SUCCEEDED
Installing golang.org/x/tools/cmd/guru SUCCEEDED
Installing golang.org/x/tools/cmd/gorename SUCCEEDED
Installing github.com/go-delve/delve/cmd/dlv SUCCEEDED
Installing github.com/stamblerre/gocode SUCCEEDED
Installing github.com/rogpeppe/godef SUCCEEDED
Installing github.com/sqs/goreturns SUCCEEDED
Installing golang.org/x/lint/golint SUCCEEDED
Installing github.com/cweill/gotests/... SUCCEEDED
Installing github.com/fatih/gomodifytags SUCCEEDED
Installing github.com/josharian/impl SUCCEEDED
Installing github.com/davidrjenni/reftools/cmd/fillstruct SUCCEEDED
Installing github.com/haya14busa/goplay/cmd/goplay SUCCEEDED
Installing github.com/godoctor/godoctor SUCCEEDED
配置vscode
{
"files.autoSave": "afterDelay",
"go.buildOnSave": "workspace",
"go.lintOnSave": "package",
"go.vetOnSave": "package",
"go.formatTool": "goreturns",
"go.goroot": "/usr/local/go",
"go.useLanguageServer": true,
"go.alternateTools": {
"go-langserver": "gopls",
},
"go.languageServerExperimentalFeatures": {
"format": true,
"autoComplete": true
},
"[go]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
}
}