Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 22 of 60 · Go

Dependency Management with Go Modules

Duration: 15 minutes

Go Modules Refresher

This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.

A module is a collection of related Go packages versioned together.

Initialising a module

$ mkdir cli && cd cli
$ go mod init github.com/yourname/cli

Adding a dependency

$ go get github.com/spf13/cobra@v1.7.0

The go.mod file now contains:

module github.com/yourname/cli

go 1.22

require github.com/spf13/cobra v1.7.0

Tidy up

$ go mod tidy   // removes unused deps, adds missing ones

Vendor directory (optional)

$ go mod vendor

Versioning

  • Tag releases with semantic versioning (git tag v1.0.0).
  • go install github.com/yourname/cli@latest fetches the latest version.

Info

Never commit the vendor directory unless you need reproducible builds without internet.

Previous: Building a RESTful API – CRUD OperationsNext: Building a CLI with Cobra