How to Install Go 1.6 on Ubuntu 16.04

How to Install Go 1.6 on Ubuntu 16.04

Go is a modern programming language developed at Google. It is increasingly popular for many applications and at many companies, and offers a robust set of libraries. This tutorial will walk you through downloading and installing Go , as well as building a simple Hello World application.

1. By using the curl download the go package

root@linuxhelp1:~# curl -O https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz
% Total% Received % XferdAverage Speed Time Time Time Current
Dload upload total spent left speed
100 80.8M100 80.8M00850k00:01:370:01:37 --:--:-- 1054k

2. Next, you can use sha256sum to verify the tarball.

root@linuxhelp1:~# sha256sum go1.6.linux-amd64.tar.gz
5470eac05d273c74ff8bac7bef5bad0b5abbd1c4052efbdbc8db45332e836b0b  go1.6.linux-amd64.tar.gz

3. Now extract the downloaded packages.

root@linuxhelp1:~# tar xvf go1.6.linux-amd64.tar.gz

go/
go/AUTHORS
go/CONTRIBUTING.md
go/CONTRIBUTORS
go/LICENSE
go/PATENTS
go/README.md
go/VERSION
go/api/
go/api/README
go/api/except.txt
go/api/go1.1.txt
go/api/go1.2.txt
go/api/go1.3.txt
go/api/go1.4.txt
.
.
.
go/test/typeswitch.go
go/test/typeswitch1.go
go/test/typeswitch2.go
go/test/typeswitch3.go
go/test/undef.go
go/test/utf.go
go/test/varerr.go
go/test/varinit.go
go/test/writebarrier.go
go/test/zerodivide.go

4. You should now have a directory called go in your home directory. Recursively change go' s owner and group to root, and move it to /usr/local

root@linuxhelp1:~# chown -R root:root ./go
root@linuxhelp1:~# mv go /usr/local

5. Set some paths in the environment.

First, set Go' s root value, which tells Go where to look for its files.

root@linuxhelp1:~# nano ~/.profile

Add the following lines at the end of the file.

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

And save the file.

If you chose an alternate installation location for Go, add these lines instead to the same file. This example shows the commands if Go is installed in your home directory:

export GOROOT=$HOME/go
export GOPATH=$HOME/work
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

With the appropriate line pasted into your profile, save and close the file. Next, refresh your profile by running.

root@linuxhelp1:~# source ~/.profile

6. For testing the install

Now that Go is installed and the paths are set for your server, you can test to ensure that Go is working as expected.

Create a new directory for your Go workspace, which is where Go will build its files.

root@linuxhelp1:~# mkdir $HOME/work

Then, create a directory hierarchy in this folder through this command in order for you to create your test file. You can replace the value user with your GitHub username if you plan to use Git to commit and store your Go code on GitHub. If you do not plan to use GitHub to store and manage your code, your folder structure could be something different, like ~/my_project.

root@linuxhelp1:~# mkdir -p work/src/github.com/user1/hello

Next, you can create a simple " Hello World" Go file.

root@linuxhelp1:~# nano ~/work/src/github.com/user1/hello/hello.go

Inside your editor, paste the code below, which uses the main Go packages, imports the formatted IO content component, and sets a new function to print " Hello, World" when run.

package main
import " fmt" 
func main() {
    fmt.Printf(" hello, world
" )
}

This program will print " hello, world" if it successfully runs, which will indicate that Go programs are compiling correctly. Save and close the file, then compile it by invoking the Go command install.

root@linuxhelp1:~# go install github.com/user1/hello

With the file compiled, you can run it by simply executing the command.

root@linuxhelp1:~# hello
hello, world

If that command returns " hello, world" , then Go is successfully installed and functional. You can see where the compiled hello binary is installed by using the which command.

root@linuxhelp1:~# which hello
/home/user1/work/bin/hello
Tag : Go language
FAQ
Q
how to download the package of GO in terminal?
A
for downloading the GO package by folowing command
# curl -O https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz
Q
what is the purpose of installing the GO in ubuntu?
A
Go is a modern programming language developed at Google. It is increasingly popular for many applications and at many companies, and offers a robust set of libraries
Q
what is the installation procedure for centos?
A
https://www.linuxhelp.com/how-to-install-go-in-centos-7/ please follow this link
Q
Where to check for latest updates of GO?
A
Please follow their official site for latest updates of GO
"https://storage.googleapis.com/golang/"
Q
How to verify your tarball for GO package?
A
We have shown that in post!! "sha256sum go1.6.linux-amd64.tar.gz"