Go is an open-source programming language that was developed by Google. It was launched in November 2009, and version 1.0 was released in 2012. It is written in C programming language C and was developed to create dependable and efficient software. Go was created to combine the best features of other programming languages into one language. In this guide, you will learn how to install Go on Ubuntu 20.04.
The advantages of the Go programming language include:
- Static(or strict) typing and compiled programming language.
- Concurrency support and Garbage collection.
- Strong library and toolset.
- Multiprocessing and advanced performance for networking.
- Good readability and usability
Let us now shift gears and install Go on Ubuntu 20.04.
Step 1. Download Go compressed file
The first step is to download the compressed source code file. At the time of writing this article, the latest version of Go is 1.16.3. So, head over to the official download page and grab the file using the wget command as follows.
$ wget https://golang.org/dl/go1.16.3.linux-amd64.tar.gz
Next, extract it to the /usr/local
directory as shown.
$ sudo tar -C /usr/local -xzf go1.16.3.linux-amd64.tar.gz
Step 2. Set the Path Variable
You need to add the path of the Go directory to the $PATH
environment variable so that the system knows where to find Go executable binaries. Run the command below to add the go binary path to the .bashrc
file This is for the case of system-wide installation.
$ export PATH=$PATH:/usr/local/go/bin
Now that we have added the PATH environment variable, run the following command to apply the changes.
$ source ~/.bashrc
Verify the version of go installed by simply running the command below. The version of go installed in the output below is 1.16.3.
$ go version
Step 3: Getting started with Go
Now that GO is installed, let’s run a simple program. Firstly, we will create a workspace directory called go:
$ mkdir $HOME/go
Inside the workspace create a new directory src/hello
.
$ mkdir -p ~/go/src/hello
Next, navigate to the directory and create a hello.go file in the hello directory.
$ cd ~/go/src/hello
$ sudo vim hello.go
Now let’s write a hello world program in go.
package main import "fmt" func main() { fmt.Printf("Hello, World\n") }
Run the program with the command:
$ go run hello.go
You can now build your projects in go.