Menu

Install Go 1.7 on Ubuntu 16.04 / 14.04 / CentOS 7 / Fedora 24

Go (often referred to as golang) is a free and open source programming language created at Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. It is a compiled, statically typed language in the tradition of Algol and C, with garbage collection, limited structural typing, memory safety features and CSP-style concurrent programming features added.

The language was announced in November 2009; it is used in some of Google's production systems,as well as by other firms. Two major implementations exist: Google's Go compiler, "gc", is developed as open source software and targets various platforms including Linux, OS X, Windows, various BSD and Unix versions, and since 2015 also mobile devices, including smartphones.A second compiler, gccgo, is a GCC frontend. The "gc" toolchain is self-hosting since version 1.7

Download and Install Go Language:

Switch to the root user.
$ su -

### Ubuntu 16.04 / 14.04 ###

# apt-get update
# apt-get -y upgrade

### CentOS / RHEL / Fedora ###

# yum -y update
Download the Go language binary package using the following command. Alternatively, you can visit Go Language download page to download the latest version of Go.
# wget https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gz
Extract the archive and move it to /usr/local. You can also place the Go lang binary to your custom location instead of /usr/local.
# tar -zxvf  go1.7.1.linux-amd64.tar.gz -C /usr/local/
Setup Go Environment variables:


Setup two important variables for Go, GOROOT (PATH) and GOPATH. Add /usr/local/go/bin to your path variable.run below command (temporary) or place the following command in /etc/profile or $HOME/.profile file for persistent across sessions.
export PATH=$PATH:/usr/local/go/bin
For Go custom location replace /usr/local/go/bin/ with /path/to/bin/ directory.


GOPATH is a Go environment variable for your project workspace. Create a workspace directory called "projectwork" in your home directory.
mkdir $HOME/projectwork
Set GOPATH variable run below command (temporary) or place the following command in /etc/profile or $HOME/.profile file for persistent across sessions.
export GOPATH=$HOME/projectwork
Verify Go Installation:
# go version
go version go1.7.1 linux/amd64
# go env

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/projectwork"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
Create your first project:
The workspace called "projectwork" located in $HOME directory. I am a root user, in my case "/root/projectwork" is my workspace. goto your workspace using below command
# cd $GOPATH
or
# cd $HOME/work
# mkdir -p src/hello
# vi src/hello/hello.go
and place the following content in the hello.go file.
package main

import "fmt"

func main() {
    fmt.Printf("Welcome To hackthesec\n")
}
Compile it with go command.
# go install hello
go command will put an executable command (hello) inside the bin directory of your workspace. Execute the executable using the following command.
# $GOPATH/bin/hello
Welcome To hackthesec
Thanks for reading..
www.hackthesec.co.in

About Author:


I am a Linux Administrator and Security Expert with this site i can help lot's of people about linux knowladge and as per security expert i also intersted about hacking related news.TwitterFacebook

Next
Newer Post
Previous
Older Post

0 comments:

Post a Comment

 
Top