Learning-Go
Published in

Learning-Go

Install Go

You can install go with your favourite package manager.

RHEL/CentOS:

dnf install golang

Ubuntu/Debain:

apt update
apt install golang

MacOS:

brew install golang

Windows:

choco install golang

Once you’ve done the install, you should now be able to access go from your terminal:

$ go version
go version go1.13.8 linux/amd64

$ go help
Go is a tool for managing Go source code.
Usage:go <command> [arguments]The commands are: bug start a bug report
build compile packages and dependencies
clean remove object files and cached files
doc show documentation for package or symbol
env print Go environment information
...

Installing Go the manual way

Package managers like apt and brew often ends up installing a slightly older version of Go. That’s because there’s usually a delay for the latest versions of Go version being packaged up and made available to the various package managers.

So if you want to get the latest version of Go, then probably the best way to do that is to download Go it from the official website.

After downloading it, you then install it. The install process various from one OS platform to another.

So for now I’m going to show you how to install Go on Linux. Go comes in the form of a single executable binary file. So installing Go is essentially a case of downloading the binary and saving it to one of your $PATH folders. However for Go to work properly you need to add the binary to the /usr/local/go/bin directory. You need create this folder if it doesn’t already exist.

mkdir -p /usr/local/go/bin

Next you need to add this folder to your $PATH setting.

echo "export PATH=~/bin:$PATH" >> $HOME/.profile

I needed to restart my terminal to load in the updated $PATH setting. Now I install the go binaries into my new folder:

cd /usr/local/go/bin
go_archive=go1.14.4.linux-amd64.tar.gz
curl https://dl.google.com/go/${go_archive} | tar xvz --strip-components=2 go/bin

The tar archive has a lot of content, including Go’s source code and documentation. But I’m just interested in extracting the go executable binaries from the go/bin folder that’s inside the archive. I’ve also used --strip-compenent setting to just extract the binaries without the folder structures. After that you should end up with:

ubuntu:~/bin$ l -ls
total 18468
14956 -rwxr-xr-x 1 root root 15312032 Jun 1 20:45 go
3512 -rwxr-xr-x 1 root root 3592206 Jun 1 20:45 gofmt

We also have a gofmt binary, that’s used for performing checks on whether go code is properly formatted.

--

--

--

This is a beginners Guide to Go

Recommended from Medium

Creating simple docker swarm management UI using Portainer and Reactjs

Moving to Gitops(Flux) with kubernetes

MySQLDump ERROR: Duplicate entry for key ‘PRIMARY’.

Transfers API: Historical Transactions 500x Faster in One Request

Weekend Things

An introduction to Blazor

Golang: pack db migration

Multithreading with RxJava

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sher Chowdhury

Sher Chowdhury

Blogger at codingbee.net

More from Medium

How to Check nil Interface in Golang?

Golang packages

GoFrame 101: Graceful shutdown

Get a file extension from a URL in Golang