Skip to main content
Installation

Install Go on Ubuntu

Go is available in Ubuntu's default repository but it may not be the latest version. Learn about installing Go Language on Ubuntu.

Sagar Sharma

The go programming language was intended to have the efficiency of C while being as simple as Python.

And there is no doubt that it is getting popular!

That's why the Go programming language is also available in Ubuntu's default repository. It may not be the latest one, but it gives you the simplest installation method.

So if you don't care about having the most recent packages, it can be installed with the single command:

sudo apt install golang

While writing, I got version 1.18.1 of the go programming language:

go version
check the installed version of go programming language

And if that's not enough and you want the most recent version, you can refer to the given guide.

Install the latest version of Go on Ubuntu

To get the most recent version, you can use the snap package of the go.

And the best part is Ubuntu comes pre-configured with snaps so no configuration is required.

But if you're running something else and want to set up snaps, you can refer to the given guide:

How to Install and Use Snap in Various Linux Distributions
Snaps are Canonical’s way of providing a cross-distribution package management system. In this article, we will see how to install and use snaps in various Linux distributions.

To install the most recent version of go using snaps, use the following command:

sudo snap install go --classic
install the latest version of go programming language on ubuntu

And as you can see, I got version 1.19.6 of the go programming language.

But that's not enough!

You will have to create a symbolic link from /snap/bin/go to /usr/bin/go to execute go programs successfully:

sudo ln -s /snap/bin/go /usr/bin/go

Run Go programs on Ubuntu

For this example, I will be showing you how you can run your first go program (a Hello world program).

Here, I will be using the nano text editor but you can use any of your preferred ones:

nano Hello.go

And it will create a file named Hello.go and open the empty new file where you have to enter the following:

package main

import "fmt"

func main() {
        fmt.Printf("Fingers crossed\n About to print Hello world!\n")
}

Once done, save changes and exit from the nano text editor.

To run the program, all you have to do is append the filename with the run flag to the go command:

go run Hello.go
run go programs on Ubuntu

Similarly, if you want to create an executable file using the following:

go build Hello_world.go

Pretty simple. Isn't it?

Looking for a text editor? Have a look at this

Just installing go won't do any fair. The best way to learn to program is to practice.

Sure, you can use Vim or nano for this purpose. But if you are a beginner, you should start with something easy that comforts you so you can focus on programming only.

And for that purpose, we have a dedicated guide on the top 8 open-source text editors for Linux:

8 Best Open Source Code Editors for Linux
Looking for the best text editors in Linux for coding? Here’s a list of the best code open source code editors for Linux.

I hope you will find this guide helpful. And if you have any queries, let me know in the comments.

Sagar Sharma