How to install Go in Ubuntu?

Go is a modern, open-source, statically typed, compiled programming language developed by Google. It is a cross-platform language available for Windows, Linux, macOS, etc. Sometimes it is also referred to as Golang because of the domain name

In this article, I will discuss how to install the Go programming language in Ubuntu.

Features of Go programming language

The go programming has the following key features –

  • Go is a statically typed and compiled programming language
  • It has a strong library and toolset
  • Concurrency support and Garbage collection
  • Multiprocessing and High-performance networking
  • Known for readability and usability (Like Python)

Installing Go from Ubuntu’s official repository

Since Go is open-source you can directly download and install it from the official repository of Ubuntu.

To install it first open the terminal and update the apt package database –

sudo apt update

Now use the given command to install go on Ubuntu –

sudo apt install golang

Press y and then enter if it asks for confirmation.

This will download and install the required packages for go programming on Ubuntu.

Installing Go from the official tarball

To install the go programming from .tar.gz archive you need to download the .tar.gz package from its official website. You can directly download it in your browser or copy the downloading link and use the given command in your terminal.

sudo wget

The next step is to extract the downloaded tarball to /usr/local directory –

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

Next set the path environment variable in  .bashrc file. First, open this file using a text editor –

nano ~/.bashrc

And then add the given line –

export PATH=$PATH:/usr/local/go/bin

Save this file and exit from the editor.

Verifying Go installation

After installing Go from any of the given methods you can verify if your installation is successful or not by using the given command.

go version

This will display the current version of go installed on your system.

Run hello world program in Go

Save the given code in a file with the .go extension.

package main

import "fmt"

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

Now use the given command to execute this code –

go run hello.go

Where hello.go is the filename. This will produce the given output.


You have successfully installed go on your system now you can start programming in go language. Now if you have a query then write us in the comments below.

Leave a Comment