This guide is based on the official “Getting started” tutorial.

In this guide we present a brief introduction to Go programming. You will:

  • Write some simple “Hello, world” code
  • Use the go command to run your code
  • Use the Go package discovery site to find packages you can use in your own code
  • Call functions of an external module


You should already have completed:

This guide is running using:

$ go version
go version go1.19.1 linux/amd64

Write some code

As with all guides, we start in our home directory:

$ pwd

Create a hello directory for your first Go source code:

$ mkdir /home/gopher/hello
$ cd /home/gopher/hello

Create the file hello.go in /home/gopher/hello:

package main

import "fmt"

func main() {
	fmt.Println("Hello, World!")

This is your first .go file! In this code you:

  • Declare a main package (a package is a way to group related code and concepts).
  • Import the popular fmt package, which contains functions for formatting text, including printing to the console. This package is one of the standard library packages you got when you installed Go.
  • Implement a main function to print a message to the console. A main function executes by default when you run code in the file.

Run your code to see the greeting:

$ go run hello.go
Hello, World!

Call code in an external package

When you want your code to do something that might have been implemented by someone else, you can look for a package that has the functionality you need.

Let’s make your printed message a little more interesting by using a function from an another package.

  1. Visit and search for a “quote” package.
  2. Locate and click the package in search results (if you see, ignore it for now).
  3. On the Doc tab, under Index, note the list of functions you can call from your code. You will use the Go function.
  4. At the top of this page, note that package quote is included in the module
  5. On the Versions tab, note the list of available versions of the module.

Packages are published in modules – like – where others can use them. Modules are improved with new versions over time, and you can upgrade your code to use the improved versions. You can use to discover published modules whose packages have functions you can use in your own code.

Modules can contain multiple packages. In the case of the the module, it contains just one package:

Let’s import the package and add a call to its Go function:

package main

import "fmt"

import ""

func main() {

To import packages from another module, your code must belong to a module. Go modules are identified by a go.mod file in a directory. A go.mod file lists the specific modules and versions providing those packages. That file stays with your code, including in your source code repository. We refer to hello as the current development module.

To create a module and its go.mod file, run the go mod init command, giving it the name of the module your code will be in (here, just use hello):

$ go mod init hello
go: creating new go.mod: module hello
go: to add module requirements and sums:
	go mod tidy

Our main package now belongs to the hello module.

We need to declare a dependency on the module, specifically version v1.5.2:

$ go get
go: downloading v1.5.2
go: downloading v1.3.0
go: downloading v0.0.0-20170915032832-14c0d48ead0c
go: added v0.0.0-20170915032832-14c0d48ead0c
go: added v1.5.2
go: added v1.3.0

go get resolves and adds dependencies to the current development module, hello in our case.

Re-run your code to see the message generated by the function you’re calling.

$ go run hello.go
Don't communicate by sharing memory, share memory by communicating.

Notice that your code calls the Go function, printing a clever message about communication.


With this quick introduction, you learned some of the basics.

As a next step you might like to consider: