How To Install Go
How To Install Go
preview
date
Jun 2, 2023
img_Link
slug
how-to-install-go
status
Published
summary
How To Install Go and Set Up a Local Programming Environment on Ubuntu
type
Post
link
tags
Tutorial
projectstype
tech
client

Step 1 — Setting Up Go

In this step, you’ll install Go by downloading the current release from the official Go downloads page.
To do this, you’ll want to find the URL for the current binary release tarball. You will also want to note the SHA256 hash listed next to it, as you’ll use this hash to verify the downloaded file.
You’ll be completing the installation and setup on the command line, which is a non-graphical way to interact with your computer. That is, instead of clicking on buttons, you’ll be typing in text and receiving feedback from your computer through text as well.
The command line, also known as a shell or terminal, can help you modify and automate many of the tasks you do on a computer every day, and is an essential tool for software developers. There are many terminal commands to learn that can enable you to do more powerful things. For more information about the command line, check out the Introduction to the Linux Terminal tutorial.
On Ubuntu 18.04, you can find the Terminal application by clicking on the Ubuntu icon in the upper-left hand corner of your screen and typing terminal into the search bar. Click on the Terminal application icon to open it. Alternatively, you can hit the CTRLALT, and T keys on your keyboard at the same time to open the Terminal application automatically.
Once the terminal is open, you will manually install the Go binaries. While you could use a package manager, such as apt-get, walking through the manual installation steps will help you understand any configuration changes to your system that are needed to have a valid Go workspace.
Before downloading Go, make sure that you are in the home (~) directory:
cd ~
Use wget to retrieve the tarball URL that you copied from the official Go downloads page:
wget https://go.dev/dl/go1.20.5.linux-amd64.tar.gz
Next, extract the downloaded archive and install it to the desired location on the system. It’s considered best practice to keep it under /usr/local:
sudo tar -xvf go1.20.5.linux-amd64.tar.gz -C /usr/local
You will now have a directory called go in the /usr/local directory.
You can set your $GOPATH by adding the global variables to your ~/.profile. You may want to add this into .zshrc or .bashrc file as per your shell configuration.
First, open ~/.bashrc with vi or your preferred text editor:
sudo vi .bashrc
Set your $GOPATH by adding the following to the file:
export PATH=$PATH:/usr/local/go/bin
Adding /usr/local/go/bin to your $PATH makes all of the Go tools available anywhere on your system.
To update your shell, issue the following command to load the global variables:
source ~/.bashrc
You can verify your $PATH is updated by using the echo command and inspecting the output:
echo $PATH
Verify the installation by checking the current version of Go:
go version