May 16th, 2016
Major problem:
System environment variable GOBIN cause problem “vim-go error: vim-go: goimports does not support srcdir”
Situation:
Recently I use vs code to write golang more than vim-go
,But when you upgrade the Golang version then use vim-go
to save file, it will always popup following error message.
vim-go: goimports does not support srcdir
Problem Environment:
- Mac Only.
- Homebrew installed only.
Root Cause:
normally there are two importnt variable in go env
which was $GOPATH
and $GOBIN
. But most user only set $GOPATH
but $GOBIN
.
It will cause your all golang binary install via go install
to the directory $GOPATH/bin
.
Recently Homebrew
formula, it will help us to set $GOBIN
but the path will be/usr/local/Cellar/go/GO_VERSION/libexec/bin
rather than $GOPATH/bin
.
What’s the problem with that?
- If you have any package which force to install in
$GOPATH/bin
, it might has problem with duplicate or not install latest one with Golang update. dlv has the same issue before,I file a PR for this. - If you already install some useful tool in
$GOPATH/bin
before, it will not update and some problem will occur. As my problem ingoimports
which is identical with issue 775, I use the old version ofgoimports
so it will occur error invim-go
.)
Solution:
- Remove all binary file
$GOPATH/bin
. (If you always use Homebrew for Golang update) - Reinstall all binaries, it will install to correct path in
$GOBIN
, not$GOPATH/bin
.