Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: cmd/go: partial GOPATH source trees, or GOPATH mounts #20535

mildred opened this Issue May 31, 2017 · 1 comment


None yet
3 participants
Copy link

mildred commented May 31, 2017

What version of Go are you using (go version)?


What operating system and processor architecture are you using (go env)?


Explanation of the issue

In projects using different languages and tools, it is difficult to always clone a Go code repository inside a GOPATH. This makes it difficult for external tools to build Go projects. What I want to achieve is:

  • Clone a go project anywhere you want
  • Run a shell script or a Makefile to build an executable, it should work

This is possible using a temporary GOPATH in the script, and symlinks, but not easy to do.


Have a GOPATH_MOUNTS environment variable containing a list of directories and their name in the go package hierarchy. Those directories will be read as if they were mounted in the GOPATH/src/source-location.

For example:


With this configuration, a package would be searched in /home/me/project/foo/a while a package would still be searched under /home/me/go/src/

Actual workarounds

I'm currently using two workarounds, mainly. The first is simple. The git repository is a gopath in itself, and won't be able to be imported. This is the case of

The other solution is to use some tricks with symlinks in the Makefile to build the project even if outside of the GOPATH. The main idea is to setup a custom GOPATH using:
mkdir -p "gopath/src/$IMPORT_PATH"
ln -s "$PWD" "gopath/src/$IMPORT_PATH"
export GOPATH="$PWD/gopath"
go build "$IMPORT_PATH"

This comment has been minimized.

Copy link

rsc commented Jun 5, 2017

On hold for package management.

@rsc rsc added the Proposal-Hold label Jun 5, 2017

@bcmills bcmills changed the title proposal: partial GOPATH source trees, or GOPATH mounts proposal: cmd/go: partial GOPATH source trees, or GOPATH mounts Feb 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.