Windows Go Tutorial: Installing Go Programming Language

Windows Go

Windows Go – In the following tutorial I will show how to install and configure your Windows Go lang development environment

 

What is Go Programming Language?

“Go is a compiledgarbage-collectedconcurrent programming language developed by Google Inc.” from http://en.wikipedia.org/wiki/Go_(programming_language)

” Go is an open source programming environment that makes it easy to build simple, reliable, and efficient software.” from http://golang.org/

Go is an open source project with a BSD-style license.” from http://golang.org/doc/install

 

 

Go Compiler

 

There are two official Go compiler toolchains: the gc Go compiler and the gccgo compiler that is part of the GNU C Compiler (GCC). I’ll start with Go Compiler but until the end of this article I’ll add more info about gcc compiler.

 

Download the Go tools

Goto Go project’s downloads page and download the version according to your system (x86/64) and start the installation 

 

Go with the installation defaults (Directory is: C:\Go) as the Go binary distributions assume they will be installed there. The installer should put the c:\Go\bin directory in your PATH environment variable. If you need to install to another location, you need to update your  PATH environment variable.

 

windows go

windows go

 

You may need to restart any open command prompts for the change to take effect.

Note that this article is using the experimental MSI installer that configures your installation automatically. If you have problems, You can also use the zip archive option that requires you to set some environment variables. For experts you can also try installing from source.

 

Test your installation

Insert the following to a file named ‘hello.go’:

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

Then run it with the go tool on command:

\> go run hello.go
hello, world
<a href="http://itekblog.com/wp-content/uploads/2012/09/hello-go.png"><img class="alignnone size-full wp-image-1528" title="hello-go" alt="" src="http://itekblog.com/wp-content/uploads/2012/09/hello-go.png" width="669" height="338" srcset="https://itekblog.com/wp-content/uploads/2012/09/hello-go.png 669w, https://itekblog.com/wp-content/uploads/2012/09/hello-go-300x151.png 300w" sizes="(max-width: 669px) 100vw, 669px" /></a>

If you see the “hello, world” message then your Go Programming Language installation is working.

 

Eclipse plugin

Prerequisites:

Eclipse

Eclipse is a decent IDE that you can use in development of your Golang code.

Download the Eclipse Standart version of eclipse (32Bit or 64Bit):eclipse-download

Java

Goto Java website and download latest version.

download-java

 

 

Goclipse

In your Eclipse goto Help > Install New Software…

eclipseInstallNewSoftware

 

In the dialog that appears, enter the update site URL into the Work with text box:

http://goclipse.googlecode.com/svn/trunk/goclipse-update-site/

Click on the Add… button.

2. Leave the Name text box empty (the name will be retrieved from the update site). Click OK.

3. Back in the Install dialog, you should see the center box filled with the category: Go Plug-in for Eclipse. Check the box next to it.

4. Click Next.

5. Read the license agreements and then select I accept the terms of the license agreements. Click Finish.

6. Restart Eclipse.

 

You’ve GoClipse plugin for Eclipse installed.

Check here for more information about the goclipse plugin.

 Create Eclipse Go Project

Click on File > New > Project…

Ec;lipse-File-New-Project

Select Go Project from the tree. Click Next.

GoProject

 

9. Enter the name of the project into the Project name text field. Click Finish.

The Go perspective will open and the new project will be visible from the Project Explorer View. See GettingStarted for more information on the new project and development tips.

 

Create new file:

new-Go-File

and choose Command Source File.

command-source

Copy the Hello, World! Example

package main
import (
   "fmt" 
)
func main() {
   fmt.Println("Hello, world.\n")
}

 

and run:

eclipse-console-run-go

 

Invalid Go language settings. Please adjust on the Go preferences page.

You’ve installed the Eclipse plugin before the Go Compiler? goto Windows > Preferences and then to the Go menu. Set the GOROOT to the installed directory of your Go Compiler (C:\Go by default). The Go Tools will be filled-in automatically.

Invalid Go language settings. Please adjust on the Go preferences page.

Invalid Go language settings. Please adjust on the Go preferences page.

If it doesn’t work, try creating a new project and test it again. It should solve the project.

 

What’s next

Read this What’s next section.

 

Go calling C

Installing mingw

In this tutorial, I won’t cover the manual installation of mingw. We’ll install mingw using the graphical Inteface for windows.

  1. Download mingw-get-inst-20120426 (or better, Download the latest installer from sourceforge)
    and run the installer…
  2. you can press the ‘next’ button until the end. if you want, you can choose to download repositories in the 3rd stage.

Installing gcc

The gcc compiler for windows require gcc only if you plan to use cgo (creation of Go packages that call C code).
As this procedure is more complex and not needed for beginners, I won’t cover this topic and we’ll continue installing Go without gcc.

 

That’s it, you have installed Windows Go !

 

Leave a Reply

Your email address will not be published.

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.