Install GO on linux


Introduction

Go is high level scripting language developed at Google by by Robert Griesemer, Rob Pike, and Ken Thompson in 2007.It is an open source programming language. It's a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.In this article we will learn installation of GO on Ubuntu.We also try for first program "Hello World" in go.


Installation : Update the repo:
$sudo apt-get update

You can install in two ways as follows: Install from CLI, It will install latest version of GO:
$sudo apt-get install golang

OR

 Downlaod specifi version of GO language by downloading package:
$sudo curl -O https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz

Extract Downloaded package:
$sudo tar -xvf go1.6.linux-amd64.tar.gz

move to /usr/local
$sudo mv go /usr/local

Setting Go Paths:
$vim ~/.bashrc

add the following lines at the end:
export PATH=$PATH:/usr/local/go/bin

Apply the changes:
$source ~/.bashrc

Check Installation of GO:
$ go
Go is a tool for managing Go source code.

Usage:

        go command [arguments]

The commands are:

        build       compile packages and dependencies
        clean       remove object files
        doc         show documentation for package or symbol
        env         print Go environment information
        fix         run go tool fix on packages
        fmt         run gofmt on package sources
        generate    generate Go files by processing source
        get         download and install packages and dependencies
        install     compile and install packages and dependencies
        list        list packages
        run         compile and run Go program
        test        test packages
        tool        run specified go tool
        version     print Go version
        vet         run go tool vet on packages

Use "go help [command]" for more information about a command.

Additional help topics:

        c           calling between Go and C
        buildmode   description of build modes
        filetype    file types
        gopath      GOPATH environment variable
        environment environment variables
        importpath  import path syntax
        packages    description of package lists
        testflag    description of testing flags
        testfunc    description of testing functions

Use "go help [topic]" for more information about that topic.

Lest try Hello World in GO:

I am using my favourite editor vim, you can use any editor.
$vim Hello.go

package main

import "fmt"

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

$ hello.go
hello, world

0 comments:

Post a Comment