Monday, June 28, 2010

Installing Go on Windows

While the Go port on Windows is not as full featured as it is for the Linux(es) or MacOS, it is still very useful to try it out on a Windows machine. In fact, for the Go language to become more and more popular, it would be very helpful if more people become involved with the Windows Go development community.

To install Go on Windows, you must:

1.) Download the binaries from the Go MinGW Builds page.

2.) Extract the binaries to a location that you can remember or that you will copy onto a clipboard. The folder containing the binaries will be called go. This go directory will contain various subdirectories (sub folders), including a subdirectory called bin, which holds the binaries (including the compiler, 8g, and the linker, 8l)

3.) Next, you should set up the various environment variables. On Windows 7, this would involve going to Start --> Hover over Computer and Right-Click --> Go to Properties

Once you're at the Properties, you go to Advanced System Settings, then click on Environment Variables.

4.) In the Environment Variables, add the following SYSTEM environment variables (by clicking on "New" for each of them, putting the name of the variable (in bold) and then putting the value specified (in italics):

- GOBIN C:\directory you put the go binaries in\go\bin

- GOARCH 386

- GOOS windows

- GOROOT C:\directory you put the go binaries in \go

Now, in order for the command line compilation to work, you have to add the GOBIN to your PATH environment variable.

To do this, find Path in the system environment variables. Edit it. Go to the end of the Path and add a semicolon, followed by %GOBIN% thusly:

somestuff;%GOBIN%

The %GOBIN% will resolve the place where you put the Go binaries, as you specified in another environment variable. This is what the percentage signs are for. They resolve the environment variable to the directory you put the binaries in. Make sure to save your changes appropriately at each step.

5.) Try out Go in a command line now. You should be able to write a source file and then try using the 8g and 8l commands. For example, write a small program in Notepad, save it as test1.go and put it where you'll remember it.

Then,

C:\workdir>8g test1.go
C:\workdir>8l test1.8

Then, you should be able to start the new executable, which if you didn't change the name using the -o option, should be:

C:\workdir>8.out.exe

Try it!

No comments:

Post a Comment