Go is installed on my Windows 7, but

I needed a break from Ruby and Ember and figured I’d take a crack at Go.

I went to golang.org and installed the msi for my Windows.
Made a “hello.go” file and ran it from the CLI successfully.

Stoked and wanting to get deeper than “hello” I looked for the next step.
Seems it’s setting up a workspace.

Go and Go/bin are in my system path variable,

Following the screencast

From C:>
mkdir gocode worked and a gocode directory was created.
but …
export GOPATH=$HOME/gocode gives me

‘export’ is not recognized as an internal or external command,
operable program or batch file.

Any clues to what I’m missing here?

1 Like

export is for linux. The equivalent for windows in this case is set GOPATH=%USERPROFILE%\gocode, although if your gocode dir is in the root of your C: drive you’d want to do set GOPATH=C:\gocode instead.

If you want to persist the setting, go to Control Panel, make sure it’s set to large or small icons (drop down setting top right), select System, then Advanced system settings and then under the tab Advanced click the button Environment Variables.... You probably want to add your GOPATH to your user variables, i.e., under User variables for <your username>.

Running go install within a project folder will compile the binary and make it available within %GOPATH%\bin and thus available on your path for execution. I usually just use go run file.go to avoid having to run two commands… Also, I sometimes forget to run go install before testing my binary and I wonder why my code changes arent working

Have you made any progress @Mittineague?

set GOPATH=C:\gocode seemed to work, at least it didn’t give any errors and went to the next prompt.

I cd’d to the gocode dir no problem

Then I got confused with the next line
~/gocode$ mkdir -p src/github.com/nf

I assume the ~/gocode$ is the prompt, and I didn’t want github.com/nf so I tried
mkdir -p src/sitepoint.com/mitt

That didn’t work so I did a bit of Googling but didn’t find anything, then got distracted, then tired, so I put it off to tackle again today.

Just curious, whats your GOROOT (where go itself is stored, this var should also be set)? ~ is a linux shortcut to /home/mitt. You seem to be storing your code at C:\gocode (I want t make sure there’s not confusion between GOROOT and GOPATH).

So for you, you should have a final path of C:\gocode\src\sitepoint.com\mitt

My recommended setup for Go on win7 would be to have your go installation at c:\go (GOROOT=c:\go) and you projects stored at c:\users\mitt\projects\go (GOPATH=c:\users\mitt\projects\go) which would make your path %PATH%;%GOROOT%\bin;%GOPATH%\bin;

You already seem to have go in your path var just fine or else ‘go’ would not be available as a command in cmd.exe. Once you set your GOPATH correctly, try the following:

go get github.com/gorilla/mux

This command should automatically fetch the gorillia/mux lib into src\github.com\gorilla\mux within your GOPATH, assuming you have git command available in cmd.exe

the -p switch on linux is create all directories in the path that don’t exist, which is default behavior on windows, so you don’t need it there. Also, you need backslashes instead of forward slashes in windows, so it becomes

mkdir src\sitepoint.com\mitt

:slight_smile:

My GOROOT is C:\Go\

My PATH is a tad overwhelming
C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\12.0\DLLShared\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Intel\Services\IPT\;C:\Program Files (x86)\Symantec\VIP Access Client\;C:\PHP;;C:\PEAR\bin;C:\Program Files\Java\jdk1.7.0_03\bin;C:\Perl\c\bin;C:\Perl\perl\bin;C:\Perl\perl\site\bin;C:\Python27;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\VirtualBox\bin;C:\Go\bin

Thanks Remon
mkdir src\sitepoint.com\mitt

Worked a treat :smile:

Yup, path is almost always large, but we can sum it up as %path%;(…whatever we are discussing)

Did that go get command work for you?

No, it says GOPATH is not set.

Okay, so have you decided if you’re going to keep it at c:\gocode or move it to your home folder?

You can set it temporarily (for the duration your cmd.exe window is open) by using the command set GOPATH=c:\gocode or permanently by following the directions Scallio gave earlier (advanced system settings). I believe you’ll need this set if you want to run certain commands such as ‘go install’

set GOPATH seemed to work though I don’t see it in the path variables.

And an empty github,com/gorilla folder was created inside gocode/src

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Allan>cd \

C:\>set GOPATH=C:\gocode

C:\>go get github.com/gorilla/mux
go: missing Git command. See http://golang.org/s/gogetcmd
package github.com/gorilla/mux: exec: "git": executable file not found in %PATH%


C:\>cd c:\gocode

c:\gocode>go get github.com/gorilla/mux
go: missing Git command. See http://golang.org/s/gogetcmd
package github.com/gorilla/mux: exec: "git": executable file not found in %PATH%


c:\gocode>

So because you set the environment variable temporarily, you would then also have to reset path to include %GOPATH%\bin. It only evaluates those variables upon start up of the command prompt. For convenience you’ll want to set it permanently.

go: missing Git command. See http://golang.org/s/gogetcmd
package github.com/gorilla/mux: exec: "git": executable file not found in %PATH%

This didn’t work because you don’t have git installed. You don’t need it unless you plan on using some third party packages in your applications, and retrieving them using the go get utility.

Ah, I thought set would add it and was wondering why didn’t “take”.

I’ve added it to my system variables now.