Go开发环境插件安装提示错误总结

    • ATOM
      • ATOM 安装运行
      • ATOM 提示gocode安装失败
      • ATOM 提示open dlv安装失败
      • ATOM 提示 GOPATH not set
      • ATOM 插件atom-ctags
    • VSCODE
      • 提示GOPATH not set
      • 提示GOPATH entry is relative错误
      • guru
    • 结语

ATOM

ATOM 安装运行

配置ATOM Go开发环境
安装script插件,可以直接在ATOM运行GO代码
Go开发环境插件安装提示错误总结_第1张图片

本人安装的插件列表
Go开发环境插件安装提示错误总结_第2张图片

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 89 03:21 .
drwxr-xr-x 11 root root     4096 89 03:21 ..
-rwxr-xr-x  1 root root  9953979 89 03:19 go
-rwxr-xr-x  1 root root 15156811 89 03:21 godoc
-rwxr-xr-x  1 root root  3036195 89 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

vscode配置go开发环境

提示$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后会自动错误检测并编译项目。

你可能感兴趣的:(Go,Golang你所不知道的技巧,Golang入门)