Skip to main content
In this lesson we cover library management in Go and the three core concepts you need to master: repositories, modules, and packages. Understanding how these pieces fit together is essential for dependency management, versioning, and publishing reusable Go libraries. A repository is the version-control location (for example, a Git repository) that holds one or more projects’ source code. Repositories are familiar from tools like GitHub, GitLab, or Bitbucket and are the usual place you store your module(s).
A dark-themed slide titled "Repository" with a purple database icon labeled "server" connected by a dotted line to a server/rack icon labeled "rep."
A module is a collection of Go packages that has a go.mod file at its root. The module is the unit of versioning and distribution in modern Go — it represents a library or an application. A module may contain one or more packages; packages are how Go organizes code into reusable units. The module is identified by its module path (import path). For published modules, this should be a globally unique path (commonly the repository import path, e.g., github.com/youruser/yourrepo). For private modules you can use a private repository path or configure your tooling to resolve private hosts.
A slide titled "Module & Packages" showing a Go module on the left branching to several packages. On the right it displays "Globally unique identifier" with the example github.com/kodekloud/learn and a v1.0.0 version tag.
Quick summary of relationships and what go.mod records:
  • Go code is grouped into packages.
  • Packages are grouped into modules.
  • Each module has a go.mod file that records the module path, the Go language version, and the other modules it depends on.
A dark-themed slide titled "Module & Packages" that explains Go concepts with two boxed points: one says Go code is grouped into packages and packages into modules, and the other explains a module lists dependencies and Go version in the go.mod file. Each point is accompanied by a colored check icon.
Definitions at a glance Creating a module — step by step
  1. Pick or create a directory where you keep your project source. In this example we create learn under a local workspace.
  2. Run go mod init with the module path. The module path should be globally unique when you intend to publish the module; otherwise use a stable private import path.
Example commands:
Expected output:
This will create a go.mod file in the learn directory. Initially it contains the module path and the Go version. As you add imports from other modules, go commands will update go.mod and create a go.sum file to lock dependency checksums.
Choose a stable, unique module path for the life of the module. If you plan to publish, use the canonical repository import path (for example, github.com/youruser/yourrepo). For private modules you can manage local overrides with the replace directive in go.mod or configure private proxy settings.
We will examine the go.mod file format, dependency versioning, and common workflows (like go get, go list -m all, and go mod tidy) in later lessons. Links and references

Watch Video