The GOPATH in Go points to the workspace. Can I create multiple projects in my workspace and have GOPATH point to a list of the locations of these projects?
2 Answers
Yes you can have multiple projects in your workspace. However, you do not specify multiple GOPATH
s for that. You simply create your two projects within that GOPATH
environment. And to compile, run etc you simply specify the entry point you want to use.
E.g.
go run src/proj1/proj1.go
go run src/proj2/proj2.go
For more information on GOPATH and workspaces, see the godoc on workspaces.
Specifically, “src contains Go source files organized into packages (one package per directory),”. Notice that you are not limited to only one main package.

- 8,810
- 5
- 40
- 42
-
2so it's workspace/src/(proj1src, proj2src etc), workspace/pkg/(proj1pkg, proj2pkg etc) and so on? Is there any way to do workspace/proj1/(src, pkg, bin)? – tldr Sep 07 '13 at 21:18
-
3What do you do if you have two projects and they need to be in two different Github Repositories? Where do you init the git project? – NateW Dec 18 '15 at 19:35
You can use single workspace but if you want to work with another project out of workspace, you should check your imports. Because when you import golang packages
import "fmt"
It searchs "fmt" package on GOROOT or other packages which is get via
go get github.com/package
It puts package under %workspace(GOPATH)%\src\github.com
. It doesn't put package under your project. So you can clone 3rd party projects under your project folder and set imports like relative path notation:
import "./github.com/package"
then run your go files. It works.