Go · Stage 0 – Before You Code · Lesson 5 of 64

Your First Go Module

Create a Go module and understand why each project needs a module name.

Create an empty folder named hello, enter it, and initialize the project with one command:

Command

go mod init example.com/hello
Line-by-line explanation
  1. go starts the Go toolchain.
  2. mod selects module tools.
  3. init means initialize a new module.
  4. example.com/hello is the module name used for learning.
Expected output
go: creating new go.mod: module example.com/hello

Go creates a small text file named go.mod in the current directory.

For a published project, the module name usually matches its repository address, such as github.com/name/project. For private practice, example.com/hello is safe and clear.