Go開發環境外掛安裝提示錯誤總結
阿新 • • 發佈:2019-01-09
ATOM
ATOM 安裝執行
本人安裝的外掛列表
ATOM 提示gocode安裝失敗
錯誤如下
:/usr/local$ go get -u github.com/nsf/gocode
go install github.com/nsf/gocode: open /usr/local/go/bin/gocode: permission denied
在/usr/local/go/bin
目錄下手動建立gocode目錄就可以解決
:/usr/local$ ls -la /usr/local/go/bin/
總用量 27504
drwxr-xr-x 2 root root 4096 8月 9 03 :21 .
drwxr-xr-x 11 root root 4096 8月 9 03:21 ..
-rwxr-xr-x 1 root root 9953979 8月 9 03:19 go
-rwxr-xr-x 1 root root 15156811 8月 9 03:21 godoc
-rwxr-xr-x 1 root root 3036195 8月 9 03:18 gofmt
:/usr/local$ sudo mkdir /usr/local/go/bin/gocode
:/usr/local$ go get -u github.com/nsf/gocode
ATOM 提示open dlv安裝失敗
go install github.com/derekparker/delve/cmd/dlv: open /usr/local/go/bin/dlv: permission denied
同樣在/usr/local/go/bin
目錄下手動建立dlv目錄就可以解決
ATOM 提示 $GOPATH not set
參考 這個
$GOPATH not set 問題解決方案
環境配置:
$ env | grep GO
GOBIN=/usr/local/go/bin
GOARCH=amd64
GOROOT=/usr/local/go
GOOS=darwin
GOPATH=/Users/ryan/go
執行安裝
sudo go get github.com/nsf/gocode
提示:
cannot download, $GOPATH not set. For more details see: go help gopath
解決方案,在安裝命令前手動指定GOPATH的環境變數:
sudo env GOPATH=XXXX(實際的GOPATH) go get github.com/nsf/gocode
ATOM 外掛atom-ctags
為了方便程式跳轉,安裝atom-ctags外掛時出現問題
At Cannot find module '/usr/lib/electron/resources/app.asar.unpacked/node_modules/symbols-view/node_modules/ctags/build/Release/ctags.node'
Error: Cannot find module '/usr/lib/electron/resources/app.asar.unpacked/node_modules/symbols-view/node_modules/ctags/build/Release/ctags.node'
at Module._resolveFilename (module.js:338:15)
at Function.Module._resolveFilename (/usr/lib/atom/src/module-cache.js:383:52)
at Function.Module._load (module.js:289:25)
at Module.require (module.js:366:17)
解決方案:
$ vim ~/.atom/packages/atom-ctags/node_modules/ctags/src/ctags.coffee
{Tags} = require(process.resourcesPath + '/../../atom/node_modules/symbols-view/node_modules/ctags/build/Release/ctags.node')
#{Tags} = require(process.resourcesPath + '/app.asar.unpacked/node_modules/symbols-view/node_modules/ctags/build/Release/ctags.node')
/usr/share/atom/resources/app.asar.unpacked/node_modules/symbols-view/node_modules/ctags/build/Release/ctags.node
VSCODE
提示$GOPATH not set
參考ATOM的方法
提示GOPATH entry is relative錯誤
如果執行時提示如下錯誤
go: GOPATH entry is relative; must be absolute path: "".
Run 'go help gopath' for usage.
exit status 2
則修改vs專案下的launch.json檔案
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {
"GOPATH": "/home/XXX/goproj:/home/XXX/project2",
"GOROOT": "/usr/local/go"
},
"args": []
}
]
}
注意不同目錄用:
區分
guru
sudo env GOPATH=/home/XXX/goproj go get -v golang.org/x/tools/cmd/guru
結語
在實際開發中,發現vscode比atom更加方便,除了支援程式碼跳轉外,vscode在外掛配置好後,在ctrl+s後會自動錯誤檢測並編譯專案。