Go Package Management

Go has developed three different types of package management through its history so far.

  • GOPATH
  • GOVENDOR
  • Go Modules

go mod is the best of all in 2021. Most of the go packages are migrating to go mod now.

GOPATH

  • Default folder is ~/go
  • GOPATH is an environment, all the packages will be stored in this environment
  • As we add more and more packages, GOPATH will become increasingly big. Imagine all codes in one repo.
  • GOPATH requires a src sub-folder under GOPATH folder

Because all packages are placed in the same GOPATH, there might be version conflicts as well.

GOVENDOR

  • Each project has its own vendor directory to store 3rd party packages
  • However, this method requires many 3rd party dependency tools, e.g. glide, dep, go dep, etc.
  • It adds more complexity and patches to the project

Go Modules

Go Module has become the de facto standard for package management. Most of the go packages are moving to the go modules.