Introduction
Go is a modern programming language developed by Google that uses high-level syntax similar to scripting languages. Go is a statically typed, compiled language in the tradition of C. This tutorial, I will walk you through downloading and installing Go on ubuntu/Kali linux.
Step-1 Download the archive file from official website
Visit the official golang website https://golang.org/dl and download the linux variant of go, extract it to /usr/local using the below command,
tar -C /usr/local -xzf go1.11.2.linux-amd64.tar.gz
Step-2 Update GOPATH and reload bashrc
Update bashrc
with GOPATH. GOPATH is for the workspace, set this location as per your preference, in my case I have it under /root/go-workspace as you can see below. GOROOT is pointing to the Go’s installation directory.
vim ~/.bashrc
To the end of the file update the path as below,
export GOPATH=/root/go-workspace export GOROOT=/usr/local/go export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
Now, refresh the .bashrc using the below command,
source ~/.bashrc
Now as the Go got installed & paths are set, Let’s ensure that its working by executing a simple “Hello, World!” program in go. Create a new file and name it hello.go and copy below code into it, which uses the main Go packages, imports the formatted IO content component, & sets a new function to print ‘hello world’
package main import "fmt" func main() { fmt.Printf("hello, world\n") }
Lets execute this,
go run hello.go hello, world
This file will output “hello world” if it successfully runs, which shows that Go is building files correctly. You can also see a binary file called hello generated. let’s try to execute that and see that the result will be same.
./hello hello world
Complete golang course:
Please checkout the full golang course from scratch here . We will continuously updating the pages with all new contents.
Installing IDE
Finally, our next step will be, to install an IDE for development. Most people use eclipse with golang plugin or intelliJ with golang plugin. The best IDE if you can buy one is the goland, its built for the golang. You can check out this blog post to learn, how to install goland on linux