How to Install Go Language on Ubuntu

Want to code in Go or run Go apps? Here are various ways of installing the Go language on Ubuntu-based Linux distros.
Warp Terminal

Google developed the Go programing language to create a language that is as powerful as C++ but follows simple syntax like Python.

And because of its efficiency, platforms such as Docker, Kubernetes, and Terraform are written in the Go language.

If you are writing code in Go or compiling a Go-based application, you must install it first.

In this tutorial, I'll show the following ways of installing Go on Ubuntu:

  • Using apt from Ubuntu repositories: Simplest option but not the latest version.
  • Using snap: Simple and often newer version.
  • Using source code: Complex method that gives you the latest version.

Let's start with the simplest and most recommended method.

If you don't care about having the most recent version, it can be installed with the following command:

sudo apt install golang

You can check if it has been installed, using the following command:

go version

While writing, you get Go version 1.18.1 which is one point release behind the most recent version:

check the installed version of go programming language

Great! So you have checked that Go is installed on your Ubuntu system. But is it working correctly? Let's check that by running a simple Go program.

Run the Simple Go program

Here, I am going to create a simple Hello world program to cross-check the installation.

I am going to use nano to create and open the file named Hello_world.go:

nano Hello_world.go

And my file contents are the following (don't judge me, I'm pro okay):

package main

import "fmt"

func main() {
        fmt.Printf("Fingers crossed\n About to print Hello world!\n")
}
hello world program for Go programming language

Save the file contents and exit Nano by pressing Ctrl + X.

Now, you will have to append the run flag and filename to the command to run the program:

go run Hello_world.go
run go programs on linux

Running as expected!

You could also build an executable Go file like this:

go build Hello_world.go

That was simple. You have Go language installed properly. Let's quickly see the removal steps.

Remove Go from Ubuntu

Since you installed it from Ubuntu's repositories using the apt command, the removal is pretty simple.

sudo apt remove golang

You can also run the autoremove afterward.

sudo apt autoremove

Method 2: ย Using snap to install a newer version of Go

This is the easiest way to get the most recent version of any package as you don't have to go through any complex rather than executing one command.

And Ubuntu comes pre-configured with snaps so why not to benefit from this? Snap can be easily installed on other distributions as well.

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 recent version of Go with snap, use the following command :

sudo snap install go --classic
install the latest version of go language in Ubuntu using snaps

And as you can see, it installed Go language version 1.19.5 which is the most recent stable release while writing.

Remove the snap Go

If you no longer need Go language installed on your system or you are just not into using snaps anymore and want to remove it, follow the given command:

sudo snap remove go

To crosscheck whether it is removed successfully, check the installed version:

go version
check go version in ubuntu

And if you get the same error, Go has been removed successfully.

๐Ÿšง
This is the most complicated method and I do not recommend this. I included it for informational purposes.

To build Go from source, visit its official download page and choose the package for your system accordingly.

visit official download page of Go programming language

Next, extract the binaries to the /usr/local directory using the tar command:

sudo tar -xzf go1.19.5.linux-amd64.tar.gz -C /usr/local/

Next, you are required to set the environment variable so that system can figure out where to look for the Go executable.

So first open the /etc/profile using the following command:

sudo nano /etc/profile

And press Alt + / to jump to the end of a line in the nano text editor and paste the following line:

export PATH=$PATH:/usr/local/go/bin
set environment variable for Go programming language in ubuntu

Now, save changes and exit from the nano text editor.

To take effect from the environment path you have just added, you will have to source the file:

source /etc/profile

Go has successfully been installed on your system. You can check the installed version:

go version
source the etc profile file on linux

How to uninstall

Removing packages installed from the source code is even more complicated. But you can remove the Go from your system by following three easy steps.

First, remove the Go binaries that you extracted while installing:

sudo rm -rf /usr/local/go

Second, remove the environment path variable form /etc/profile:

sudo nano /etc/profile
remove go programming language when installed from source

And third, source the file to apply the changes:

source /etc/profile
Command 'go' not found on Ubuntu

Looking for an open-source IDE to run Go programs?

So you learned to install Go on Ubuntu Linux. You also ran a simple Go program. But if you have to write programs in Go, you'll be better off with a proper code editor.

I use VSCode for my daily coding tasks but this can't be the same for you.

So we have compiled a list of modern open-source IDEs on which you can run your Go programs efficiently:

7 Best Modern Open Source Text Editors For Coding in Linux
Looking for the best text editors in Linux for coding? Hereโ€™s a list of the best code editors for Linux. The best part is that all of them are free and open-source software. If you ask experienced Linux users, their answers would probably include Vim, Emacs, Nano, etc. No

And if you are a VSCode user like me and looking for an alternative, you can use the VSCodium 100% open-source version of Microsoft VSCode.

Please use the comment section for any queries related to this guide or suggestions on what I should cover next.

About the author
Sagar Sharma

Sagar Sharma

A software engineer who loves to write about his experience with Linux. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

itsfoss happy penguin

Great! Youโ€™ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.