13

I am pretty new to Go and Gogland. I just downloaded 'go1.8.3.windows-amd64.msi', installed it in C Drive and then started writing my programs in a notepad and then finally running it from a terminal.

I am facing some issues with Gogland. I have intelliJ IDEA Ultimate But I have been asked to use Gogland. I do not know whether this is the correct decision. You may want to advise me on the same. I just created a new project, gave it a name and added a go file into it which has simple helloworld code. But it shows me an error "GOPATH is empty".

Gogland editor

As you could see the message at the top, just above the line package myfirstproject.

How to resolve it? Do I need to do something with environment variables. The PATH environment variable is already set to 'C:\Go\bin'.

When I click on the error message it asks me to configure GOPATH.

enter image description here

James Z
  • 12,209
  • 10
  • 24
  • 44
Shinchan
  • 331
  • 1
  • 3
  • 13
  • 4
    I don't see a question, are you asking _what_ to set GOPATH to? You can refer to the documentation: [How to Write Go Code](https://golang.org/doc/code.html) – JimB Jun 12 '17 at 15:12
  • Thanks!The link is very helpful for beginners like me.Can you suggest some tutorials for Gogland IDE.Whatever tutorials I found are not that descriptive.I mean a fresher like me would expect details like what to do with various settings in Gogland etc. Jetbrains have given excellent documentation for intelliJ IDEA but as far as Gogland I think it is not that descriptive. – Shinchan Jun 13 '17 at 05:18
  • Well Gogland is still in beta/EAP, so it's intended for experienced users to test out, and you may need to discover many of the features and interfaces on your own as they evolve. I'm sure better documentation will be written, but things are still subject to change. – JimB Jun 13 '17 at 12:46

2 Answers2

18

As of Go 1.8, the default GOPATH value is /go.

GOPATH is where your source code will live. You can either use the default one or use a custom one, for example, I use D:\go.

The IDE has not detected the GOPATH because none was set. When you download Go you are also presented with the installation instructions, please have a look at that as well.

dlsniper
  • 7,188
  • 1
  • 35
  • 44
  • 1
    Thanks! I think you are correct.I went to File-> settings->GOPATH.Added the value C:\GO\bin and then ran my program.It worked.Also GOROOT contains the value GO1.8.3(C:\GO) – Shinchan Jun 13 '17 at 05:14
  • 2
    That would be incorrect as GOPATH and GOROOT must be different from each other. As of Go 1.8, the default GOPATH value is /go. – dlsniper Jun 13 '17 at 07:53
  • You mean to say the values I have in GOPATH and GOROOT are wrong.If that is true then I do not understand how my programs are running.I did not manually give the value for GOROOT.The value was already there.I mean by default it had that value.I only entered the value for GOHOME.Also can you suggest how to resolve it? – Shinchan Jun 13 '17 at 14:47
  • You don't need to touch GOROOT, that one is implicit when you configure the Go SDK (or when the IDE detects it automatically). The value that you need to configure, GOPATH, must not be set into where you installed Go. in the description you've posted it looks like you've set GOPATH = GOROOT, which is why I've posted the reply. Just set the GOPATH as described (and not in GOROOT). Your apps compile because you currently probably aren't using any packages / dependencies in your code. If you want to learn Go, you can join the Gophers Slack https://invite.slack.golangbridge.org/ and get more info – dlsniper Jun 13 '17 at 19:00
1

Check if the directory ~/go exists (%USERPROFILE%/go for Windows). If not, create it.

TLDR:

Go tools expect a certain layout of the source code. GOROOT and GOPATH are environment variables that define this layout.

GOROOT is a variable that defines where your Go SDK is located. You do not need to change this variable, unless you plan to use different Go versions.

GOPATH is a variable that defines the root of your workspace. By default, the workspace directory is a directory that is named go within your user home directory (~/go for Linux and MacOS, %USERPROFILE%/go for Windows). GOPATH stores your code base and all the files that are necessary for your development. You can use another directory as your workspace by configuring GOPATH for different scopes. GOPATH is the root of your workspace and contains the following folders:

src/: location of Go source code (for example, .go, .c, .g, .s).

pkg/: location of compiled package code (for example, .a).

bin/: location of compiled executable programs built by Go.

To change GOPATH for GoLand, see here.

Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219