Hello World Barrier Help!

Hi,

I cannot tell for sure what’s wrong, but I would do these steps:

  1. Call

     go env GOPATH
    

and verify if the output is the GOPATH that you would expect.

  1. Place any .go file under $GOPATH/src. You can use a subdirectory here; as an example, let’s call it “helloworld”. If your .go file is called main.go, your Go workspace should now look like this (where GOPATH is the output from go env GOPATH:

     GOPATH
     +-- src
     |   +-- helloworld
     |       +-- main.go
     +-- pkg
     +-- bin
    

Now cd into GOPATH/src/helloworld and edit main.go.

A basic hello world code is:

package main

import "fmt"

func main() {
    fmt.Println("Hello, world!")
}

Save the file and run

go run main.go

and you should get a “Hello, world!” back. (No binary file is created in this case.)

Then run

go build main.go

and you should get a binary next to your source file. And if you run

go install main.go

you should find the binary in GOPATH/bin.

3 Likes