Installation of Go on Linux (golang)

Author
By Darío Rivera
Posted On in Go

The programming language Go is a compiled, statically typed language that uses a concurrency mechanism capable of making the most of multi-core and network architectures, also allowing the construction of flexible and modular programs. Go was created in 2009 by Robert Griesemer, Rob Pike and Ken Thompson, the latter also being the creator of the B language (predecessor of C). Some well-known applications have been created in Go such as Docker, Kubernetes and Ethereum.

Installation

In Debian-based distributions you can install it directly from the repos with the following command:

sudo apt-get install golang

This command will install the compiler and create a folder called go in ~($HOME). To verify that everything has been installed correctly, you must create a simple program, compile it, and run it.

cd ~/go/src
mkdir helloworldapp && cd helloworldapp

While in this directory, you must create a file with vim, nano, or any other editor with the following content:

package main

import "fmt"

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

And finally, compile and run it.

go build
./helloworldapp

The output of this program will be as follows:

hello, world

Configuration

As you may have noticed, the directory ~/go/src is the default directory where language program files (workspace) should be created. To change this directory, you must configure the GOPATH environment variable by adding the following line of code in the startup file of the shell you use.

export GOPATH=$HOME/go

Bash

You must edit the ~/.bash_profile file and then run the following command.

source ~/.bash_profile

Zsh

You must edit the ~/.zshrc file and then run the following command.

source ~/.zshrc

See you soon!


Acerca de Darío Rivera

Author

Application Architect at Elentra Corp . Quality developer and passionate learner with 10+ years of experience in web technologies. Creator of EasyHttp , an standard way to consume HTTP Clients.

LinkedIn Twitter Instagram

Sólo aquellos que han alcanzado el éxito saben que siempre estuvo a un paso del momento en que pensaron renunciar.