Getting started with Go

Time to learn another language because I've got a restless brain. Next up Go.

Installation

Go is simple to install. You can install it on a Mac with

brew install go

I’m on Arch Linux and go is available in the main repositories. Packages are available for most Linux distros and you can always compile from source if you want.

pacman -S go

On Windows there is an .msi installer.

After you’ve installed go you can get some help with

go help

The inevitable Hello World

As with every programming language you’ll want to run a hello world. Create a file ‘hello-world.go’ and add the code below.

package main

import "fmt"

func main() {
  fmt.Println("Hello World")
}

You can run the code with

go run hello-world.go

You can also build your hello world program into a binary

go build hello-world

You can now run the compiled code with

./hello-world

Now time to start learning!

Tags

Can you help make this article better? You can edit it here and send me a pull request.

See Also