0

I just tried installing Go following the official doc: https://golang.org/doc/install#install

However, I encountered a problem when I tested the installation.

I created the hello.go file like the example in the doc. I can go build hello.go successfully, but I cannot run the compiled binary file. Moreover, I can go run hello.go.

heyuan@pop-os:~/Other/temp$ cat hello.go 
package main

import "fmt"

func main() {
        fmt.Printf("hello, world\n")
}
heyuan@pop-os:~/Other/temp$ go build hello.go 
heyuan@pop-os:~/Other/temp$ ls
hello  hello.go
heyuan@pop-os:~/Other/temp$ hello

Command 'hello' not found, but can be installed with:

sudo snap install hello              # version 2.10, or
sudo apt  install hello            
sudo apt  install hello-traditional

See 'snap info hello' for additional versions.

heyuan@pop-os:~/Other/temp$ go run hello.go 
hello, world

Here are my environment variables

export GOROOT=/usr/local/go
export GOPATH=/home/heyuan/Software/go
export PATH=${GOROOT}/bin:${PATH}:${GOPATH}/bin
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Heyuan Li
  • 21
  • 4

1 Answers1

1

In bash you can run the executable putting ./ before the file.

In your case you have to do:

./hello

If the executable is in another folder, than you need to specify the path:

/opt/SP/executable/hello
alessiosavi
  • 2,753
  • 2
  • 19
  • 38