Skip to content

Multiple GOPATHs

RaduBerinde edited this page Feb 4, 2016 · 5 revisions

Sometimes you want to work on different changes in parallel - most importantly, to be able to run a slow test on one change while developing another change. For this we need multiple clones of our repository (or multiple worktrees, see git-worktree.

Because of the way package paths work in go having multiple copies of the same repository in the same GOPATH is difficult to achieve. The solution simply to set up multiple GOPATHs. Each directory will have a full copy of all project dependencies. We could set up /go and /go2.

export GOPATH=/go
export PATH=$PATH:$GOPATH/bin
mkdir -p $GOPATH/bin $GOPATH/pkg $GOPATH/src/github.com/cockroachdb
cd $GOPATH/src/github.com/cockroachdb
git clone [email protected]:UserName/cockroach.git  # Replace with your username
cd cockroach
make
# Repeat the above with GOPATH=/go2

We can set up some symlinks to easily go to each repository:

ln -s /go/src/github.com/cocroachdb/cockroach ~/roach
ln -s /go/src/github.com/cocroachdb/cockroach ~/roach