Go Language Tutorials: Environment Setup

Go Language Tutorials: Environment Setup

Go Language Tutorials


Environment Setup

If you want to set up your environment for the Go programming language, you will need the following software installed on your computer -

Text Editor

Go compiler


Text Editor

To write your programs you will need a text editor. For examples, EMACS, Windows Notepad, etc

Different operating systems have different names and versions of text editors. For example, vim can be used on Windows and Linux, but Notepad is only used on Windows.

The files which contain the program source code are called source files. The source files for Go programs have the extension “.go”


Before start writing your program, make sure you have enough experience to write a computer program, save it in a file, compile and finally execute it.


Go Compiler

The source code written with the help of any text editor is in the human-readable source for your program. The program needs to be compiled to be turned into machine language so that your CPU can execute it as per the instructions given. The Go compiler compiles the source code into its final executable program.

The Go compiler comes as binary installable for Linux, Mac OS X(Snow Leopard and above), and Windows OS with 32-bit and 64-bit processor architectures.


Download Go

Go installable file can be downloaded from here.

I have a windows machine so I have downloaded the one with the “.msi” extension.


Installation on FreeBSD, UNIX/Linux, and Mac OS X

Download the archive and extract it into the folder /usr/local, creating a Go tree in /usr/local/go.

And then add /usr/local/go/bin to the PATH.


Installation on Windows

To install on windows use the MSI file and follow the steps in the installation prompts to install the Go tools. By default, the Go language is installed in c:\Go. You should set the c:\Go\bin directory in the Windows PATH environment variable.


Verify the Installation

Create a source file named HelloWorld.go in c:\Go

Write a code below in HelloWorld.go

package main
import "fmt"
func main(){
     fmt.Println("Hello World")
}

Now run HelloWorld.go using the following command to see the result -

C:\Go>go run HelloWorld.go

Output

Hello World

Post a Comment

0 Comments