Linux

Setup Go in Linux is straight-forward. All you have to do is identify your CPU architecture and operating system (you already did!) and you're good to go. Let's begin.

Preparing Installation

Identify Your CPU Architecture

The fastest and easy way is to identify your CPU architecture is using the command: $ uname -m

u0:cerigo$ uname -m
x86_64

This will dump the CPU architecture out. However, it's not the context that we want. You need to take this text and cross-check with the uname list (available at: https://en.wikipedia.org/wiki/Uname)

Normally, these output are:

x86_64     --> amd64
i386       --> i386
i686       --> i386
x86        --> i386
i686-AT386 --> i386
aarch64    --> arm64
armv6l     --> armv6l
ppc64      --> ppc64le

We already know we're on Linux so we can skip the operating system identifications.

Install Go Programming Language Compiler

Download The Installer Package

You can now download the installer package from the official site: https://golang.org/dl/ and search for anything linux and your CPU architecture. Download the tar.gz file.

Example, for version 1.13.1, Linux, amd64, it is: go1.13.1.linux-amd64.tar.gz.

NOTE:

  • I strongly DO NOT recommend you to install Go compiler in any other ways like Ubuntu-PPA or native. Their implementations involved dissecting the compiler parts to fit in their operating system, making the compiler creating all forms of weird and rare issues that we haven't seen.
    • The compiler source codes are meant to be in one body and that's it. Breaking it means you will find it tough to ask for help.

Follow Their Installation Instructions

As part of continuous improvements, their instructions for installation is also changing from time to time so please follow step-by-step accordingly here: https://golang.org/doc/install. In summary, you will do something like these:

1. Un-compress to /usr/local

Un-compress the tar file and load the compiler to /usr/local

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

2. Script Environment Configurations

Script the PATH-ing. You do either one:

    • To /etc/profile command (effective per login. Logout then Login effort is required):
echo '#!/bin/sh
export GOROOT="${GOROOT:-"/usr/local/go"}"
export PATH="${PATH}:${GOROOT}/bin"
export GOPATH="${GOPATH:-"$(go env GOPATH)"}"
export PATH="${PATH}:${GOPATH}/bin"
if [ ! -z "$GOBIN" ]; then
        export PATH="${PATH}:${GOBIN}"
fi
' > /etc/profile.d/go.sh
    • To $HOME/.bashrc command (effective per opening terminal):
echo '
export "PATH=${PATH}:/usr/local/go/bin"
export "PATH=${PATH}:$(go env GOPATH)/bin"
if [ ! -z "$GOBIN" ]; then
        export PATH="${PATH}:${GOBIN}"
fi
' >> $HOME/.bashrc

3. Update Current Terminal

3. Source the updated PATH-ing file depending on what you did in previous step.

    • either:
source /etc/profile
    • or:
source $HOME/.bashrc

4. Test The Go

To easily test the setup, you can do the type check against go:

$ type -p go
/usr/local/go/bin/go

If it returns the binary path, it means the pathing setup was successful.

5. Logout and Login (Optional)

If you save the path-ing into /etc/profile.d, I would recommend you to logout and then to login into again for the environment variables to effect effects.

/etc/profile only works at login stage, not each terminal opening stage.


However, if you saved it into $HOME/.bashrc, you can skip this step as the next terminal opening would have the pathing set there.

About GOPATH and GOBIN
Starting from version 1.8, GOPATH and GOBIN by default, if unset, are set to:
* Darwin & Linux: $HOME/go
* Windows: %USERPROFILE%\go

Hence, it is no longer a mandatory to set both of them. You only need to set them when you are having custom path. Example:
1. you would want all the go binary from installed from go get to be stored in GOBIN.
2. you would want go to operate in a specific workspace specified in GOPATH.

Read-up: https://github.com/golang/go/wiki/SettingGOPATH

Install Git Software

Git is packed in your standard packages distribution. Install it via that channel.

Setup

Depending on your distribution, to do that, you use:

Debian based:  $ sudo apt-get install git -y
RPM based:     $ sudo yum install git -y

Install Text Editor

Depending on your needs and taste, Linux operating system packed quite a large number of open-source text editors. My favorite one would be vim (and always vim). My reason because I like everything works in a single terminal, and without extra installations, setup procedures, etc. When using vim, I can get extra experience dealing with terminal, which is essential to using git. When performing network routines like SSH terminal editing, I can just vim it and get the job done.

However, please keep in mind that learning vim from start without mentoring can be a nightmare experience. If you wish to proceed, go ahead with:

Debian based:  $ sudo apt-get install vim -y
RPM based:     $ sudo yum install vim -y

There are other free and open-source code editors like Atom, Visual Studio Code, and Bracket. Please do not get too adventurous so that the community can support you.

That's all about setting up Go programming language in Linux. You are now having a fully compliant and working Go compiler.