Learn the Go Programming Language: Start Here

The Go programming language (aka Golang) is a versatile programming language that is used for building low-level infrastructure, web applications and services, cloud native applications, distributed systems, networked applications, concurrent processing tasks, networking tools, proxies and command-line tools, and also works well for containers, IoT and embedded systems.
The main reason why Go is so popular is its speed. Developers who use Golang as their go-to option will tell you that it has one of the fastest compile times of any language.
Unlike Python, Go is a compiled language that is statically typed, explicit and modeled after the C programming language. Even so, Go was inspired by the simplicity of Python. And because Go uses goroutines (a lightweight execution thread and function that executes concurrently with the rest of a Go program), it can produce programs that are able to run multiple processes at the same time (concurrency).
Go was created in 2007 by Google to eliminate some of the issues that they identified when developing software internally (such as slow build times and better concurrency). Google also wanted to create a language that would help make the development process more productive and scalable. What they ultimately wanted was a simple, efficient and easy-to-use programming language.
Hence, Golang.
Pros and Cons of Golang
PRO | CON |
Simplicity and easy to learn and use | Allows for sloppy coding practices |
Concurrency | Lack of libraries |
Fast compilation | Static typing can create less flexible code |
Built-in testing (with good error messages) | Comparatively small community |
Garbage collection | While compile time is very fast, compiled code isn’t the fastest. |
Can use all CPU cores efficiently | No inheritance |
Best-in-class documentation | |
Fairly powerful profiling tools | |
Eliminates the distinction between synchronous and asynchronous code |
Now that you have an understanding as to why Go was created, let’s get into how it’s used.
As with everything in the world of programming, if you’re not familiar with the language, it’s always best to start from the beginning. With Go, the beginning starts with installation. I’m going to show you how to get Go up and running on a daily build of Ubuntu Linux 24.04. If you use a different Linux distribution (or macOS or Windows), you’ll need to alter the installation instructions as needed.
Installing Go on Ubuntu Linux
Before you can use Go, it must be installed. There are several methods for installing Go, but we’ll stick with the two primary paths. Since we’re dealing with Ubuntu, one route to installing Go is via Snap, which is done with this command:
1 |
sudo snap install go --classic |
If you’re not a fan of Snap packages, you can instead install it via apt and the standard repositories with this command:
1 |
sudo apt-get install golang-go -y |
You can verify the installation was successful with this command:
1 |
go version |
You should see something like this in the output:
1 |
go version go1.22.1 linux/amd64 |
Congratulations, the Go language is ready to … go!
Your First Go Application
As you’ve probably predicted, the first application we’ll create is “Hello, World” — because that’s where every language tutorial should begin.
Create a new directory to house your Go projects:
1 |
mkdir go_projects |
Next, change into that directory:
1 |
cd go_projects |
Now create the “Hello, World” file with this command:
1 |
nano hello.go |
In that file, paste the following:
1 2 3 4 5 6 7 |
package main import "fmt" func main() { fmt.Println("Hello, New Stack") } |
What does it all mean? Let’s break it down, line by line.
- package main: This line calls the main package, which is included with Go.
- import “fmt”: This imports the package that is used to format basic strings, values, inputs, and outputs.
- func main(): This is a special type of function, and it is the entry point of the executable programs. Every executable program must contain this function.
- fmt.Println(“Hello, New Stack”): This uses the default formats for its operands and writes to standard output.
Save and close the file.
To compile and run the application, issue this command:
1 |
go run hello.go |
The output will be:
1 |
Hello, New Stack |
You’ll notice that Go does not create an executable file. Unlike languages like Python, Go includes the ability to generate an executable application from your .go file. Sticking with our hello.go file, the command for this would be:
1 |
go build hello.go |
After you run this, you’ll find a new file in the directory called hello. To run the application, issue the command:
1 |
./hello |
You should see the same output as you did before. The big difference is that you can copy that application to any machine (as long as it’s running the same OS). If you want to cross-compile, that’s when you’ll run into trouble. Why? Because the default go build command assumes you’re building for the same OS and architecture.
Let’s say, however, you want to build the Hello app on Linux but want it to run on a macOS machine. For that, you’ll have to add a few options to the command. The options are as follows:
- GOOS: defines the OS to be compiled for
- GOARCH: defines the architecture to be compiled for
For instance, say you want to compile the application to run on an Intel-based MacOS machine. That command would be:
1 |
GOOS=darwin GOARCH=amd64 go build hello.go |
For an Apple Silicon Mac, that command would be:
1 |
GOOS=darwin GOARCH=arm64 go build hello.go |
To list all of the operating systems and architectures, issue this command:
1 |
go tool dist list |
You should see a full list of all the combinations that are available for cross-compiling your Go app.
Congratulations on taking your first steps with the Go language. Next time around we’ll continue by digging a bit deeper into the language.