When I run go get -v -x test, all goes well, it downloads the dependencies and build out an executable. But when I run go get -v -x -pkgdir pkg-1 test, it leads to an error:
What is it that you think the -pkgdir flag should do in this case and what are you actually trying to do here?
Here is the description for the pkgdir flag:
install and load all packages from dir instead of the usual locations. For example, when building with a non-standard configuration, use -pkgdir to keep generated packages in a separate location.
I feel like you have confused the go install and/or the go build commands with the go get command which is what you mainly use if you need to install remote packages, not to install local packages which I think you’re trying to do.
Why not just use go get -u pkg if you need to update the dependencies of the package and then use go build or go install afterwards to install the actual package?
The -u flag instructs get to use the network to update the named packages and their dependencies. By default, get uses the network to check out missing packages but does not use it to look for updates to existing packages.
I don’t know, but for what it’s worth it works for me (not that I’ve ever used it before):
jb@unu:~ $ go get -v -pkgdir /tmp/foo github.com/calmh/du
runtime/internal/sys
runtime/internal/atomic
...
github.com/calmh/du
jb@unu:~ $ ls -l /tmp/foo
total 8520
-rw-r--r-- 1 jb staff 3748 Mar 31 11:53 errors.a
drwxr-xr-x 3 jb wheel 102 Mar 31 11:53 github.com/
drwxr-xr-x 3 jb wheel 102 Mar 31 11:53 internal/
...
jb@unu:~ $ go version
go version go1.8 darwin/amd64