How to Install Go on Ubuntu

What is Go?

Go is an open source, compiled, concurrent, garbage-collected, statically typed language developed at Google. Google created it to solve its own problems in relation to multicore processors, networked systems and large codebases. While languages such as C and C++ are fast, they are hard to master and development takes longer. While Python is easier to work with, it compromises on runtime efficiency. Go was designed to be efficient, scalable and productive. This programming language designed by Google engineers Robert Griesemer, Rob Pike, and Ken Thompson.

Install Go

  • Use curl or wget to download the current binary for Go from the official download page. As of this writing, the current version is 1.11 Check the download page for updates, and replace 1.11 with the most recent stable version if necessary.
curl -O https://storage.googleapis.com/golang/go1.11.linux-amd64.tar.gz
  • Extract the tar file:
tar -xvf go1.11.linux-amd64.tar.gz
  • Adjust the permissions and move the go directory to /usr/local:
sudo chown -R root:root ./go
sudo mv go /usr/local

Adjust the Path Variable

Using a text editor, open the ~/.profile file and add the following two lines to the bottom of the file:

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

Save the file, and load the commands into the current shell instance:

source ~/.profile

Test the Installation

According to the official documentation, the following steps are the recommended way to test the success of the installation:

In your home directory create a folder named go, this will be your workspace:

mkdir go

Within that directory create /src/hello and within that directory copy and paste the contents of the file below:

mkdir -p go/src/hello && cd go/src/hello
touch hello.go
package main

import "fmt"

func main() {
fmt.Printf("hello, world\n")
}

Build the hello.go file:

go build

Run the script:

./hello

hello, world

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. I am a tech blogger and an IoT Enthusiast. I am eager to learn and explore tech related stuff! also, I wanted to deliver you the same as much as the simpler way with more informative content. I generally appreciate learning by doing, rather than only learning. Thank you for reading my blog! Happy learning! Follow and send tweets me on @harshvardhanrvm

Leave a Reply

%d bloggers like this: