Skip to the content.

Your first program

This lesson covers some history of Go and also teaches you how to build your first Go app.

Watch the video your first Go program

Introduction

In this lesson we’ll cover:

A history of Go

The language is called Go but is sometimes known as Golang as the first website for it was golang.org.

Go was created in 2009 by Robert Griesemer, Rob Pike and Ken Thompson. It’s hard to estimate the number of Go developers but it’s somewhere between 1.1 and 2.7 million, quite a sizeable amount. More than 2500 companies are using Go including, Google, Pinterest and Uber. So, you see, used by a lot of folks by big companies.

Why was Go created?

As is often the case, a programming language is created to deal with the shortcomings of other languages. In this case, the creators wanted this new language to have the following capabilities:

It seems the creators agreed on disliking C++ :)

What is it used for though?

Here’s some areas where you are likely to find a Go being used:

References

There are many great resources out there for learning the Go programming language like:

Features

So, what features makes Go compelling? Well, there are some features worth mentioning:

Install Go

Ok then, hope you are intrigued at this point and just want to see some code? Of course, you are :)

Make sure you’ve followed the instructions for installing Go on your machine.

https://go.dev/doc/install

A Go program

Here’s what a first program can look like:

package main

import "fmt"

func main() {
 fmt.Println("hello")
}

The program in detail

Commands

Now that you have a program, there’s two things you might want to do:

Run your app

To run your app, type go run <file>.go, for example:

go run main.go

Build your app

To produce an executable, run go build <file>.go, for example:

go build main.go

It produces an executable, on MacOS and Linux that’s a file with -X as permission, on Windows, it’s a .exe file.

Congrats, you’ve created your first Go application.

Summary

In this article, you learned about the programming language Go, some features it has and how to write your first program.

🚀 Challenge

Compare Go to other programming languages, can you list some differences between them?

Review & Self Study

Select one of the resources below and try do a tutorial.

Assignment

Create a file main.go. Use the fmt library to print out to the console. Remember that your run programs with go run <my program>.go.

Solution

Create a file main.go

package main

import "fmt"

func main() {
  fmt.Println("printing to the console")
}