Skip to main content

How to install Go 1.18 on Ubuntu 22.04

In this tutorial, we are going to explore how to install go on Ubuntu 22.04

Golang is an open-source programming language that is easy to learn and use. It is built-in concurrency and has a robust standard library. It is reliable, builds fast, and efficient software that scales fast.

Its concurrency mechanisms make it easy to write programs that get the most out of multicore and networked machines, while its novel-type systems enable flexible and modular program constructions.

Go compiles quickly to machine code and has the convenience of garbage collection and the power of run-time reflection.

In this guide, we are going to learn how to install golang 1.18 on Ubuntu 22.04.

Go is not yet released. There is so much work in progress with all the documentation.

The changes that have been introduced are the following:

  • Go 1.18 includes an implementation of generic features. This include backward-compatibity changes to the language.
  • The syntax for function and type declarations now accepts type parameters.
  • Parameterized functions and types can be instatiated by following them with a list of type arguments in square brackets.
  • the syntax for interface types now permits the embedding of arbitrary types as well as union.
  • The new predeclared identifier any is an alias for the empty interface. It maybe used instaead of interface {}.
  • The go 1.18 compiler now correctly reports declared but not used errors for variables that are set inside a function literal but are never used.
  • The go 1.18 compiler now reports an overflow when passing a rune constant expression.
  • Go 1.18 introduces the new GOAMD64 environment variable which selects a version of AMD64 architecture.
  • Go get no longer builds or install packages in module-aware mod.
  • gofmt now reads and formats input files concurrently with a memory limit proportional GOMAXPROCS.
  • The vet tool is updated to support generic code.
  • The garbage collector now includes non-hip sources of garbage colector work when determining how frequently to run.

# Installing Go 1.18 on Ubuntu 20.04

# 1. Run system updates

To begin with, we need to run system updates in order to make our current repositories up to date. To do so we need to run the following command on our terminal.

sudo apt update && apt upgrade -y

When both upgrades and updates are complete, go ahead to download go from its download page.

# 2. Installing Go

To install go we need to download it from go download page. we are going to download the beta release. We are going to use the curl command to download.

curl -LO https://go.dev/dl/go1.18beta1.linux-amd64.tar.gz

when the download is complete, extract the archive downloaded to your desired location. I will be using** /usr/local** directory.

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

After extraction is complete move ahead and set up the go environment.

# 3. Setting Go Environment

To set up go environment we need to define the root of golang packages. We normally use **GOROOT **and GOPATH to define that environment. We need to set up the GOROOT location where the packages are installed.

export GOROOT=/usr/local/go

Next, we will need to set up the GOPATH. Let’s set up GOPATH in the $HOME/go directory.

export GOPATH=$HOME/go

Now we need to append the go binary PATH so that we can be able to access the program system-wide. Use the following command.

export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

To apply the changes we have made above, run the following command:

source ~/.bashrc

Lastly, we can do the verification with the following;

go version
go version go1.18beta1 linux/amd64

Let’s create a program to check all our settings. We will create a simple one.

Create a file main.go on the main directory.

touch main.go

On your favorite text editor do the following

sudo nano main.go

Insert the below code

$ package main

import "fmt"

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

To run the program use the following command;

go run main.go
Hello Nextgentips

# Conclusion

Now you know how to install golang 1.18 in Ubuntu 20.04. You can consult the go documentation in case you have any problems.