如何在多个平台上通过Dropbox(或类似方式)共享GOPATH

I develop across 3 different platforms, Windows, OS X and Ubuntu Linux.
I use Dropbox to synchronize my code between all 3 platforms.
The problem I have is compiled binaries on OS X and Linux get the same name, so binaries in my GOPATH are always overwriting each other. I don't have this problem with Windows because binaries always compile with a .exe extension.

Has anyone else experienced this problem, and if so, how did you get around it?

1- set GOBIN to separate path (just e.g. for OS X) and use

go install

Command go :

If the GOBIN environment variable is set, commands are installed to the directory it names instead of DIR/bin. GOBIN must be an absolute path.


2- Also you may rename the output file:

go build [-o output] [-i] [build flags] [packages]

Like this:

go build -o newname

The -o flag, only allowed when compiling a single package, forces build to write the resulting executable or object to the named output file.


Also see: How do I use a Samba server location for GOPATH?

The solution is simple: only share the $GOPATH/src folder across your computers, there is really no need to share the complete $GOPATH as package objects ($GOPATH/pkg) and binaries ($GOPATH/bin) compiled to one platform have no real use on other platforms, and they are reproducible by a simple compilation.

This will also reduce the storage and bandwidth. If for some reason you would still need the compiled binaries for other platforms, the go tool has built-in support for cross compilation, e.g. GOOS=windows go build will simply produce you the Windows executable binary of the package whose folder you're in in any OS, placed in the current folder (you can also change the architecture with GOARCH).

Another option would be to put your code under a source control e.g. git (github.com), which also preserves history. The go tool also has support to easily get the source code from a git repository, e.g. go get -u github.com/youruser/yourpackage.