Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go error: no Go files in /usr/lib/go/src/go

I'm having some trouble with my go installation in Arch Linux. I installed go a while ago, and haven't touched my installation in a few months. At the time, it was working, however.

When I run the following program, test.go, with go run test.go,

package main

import "fmt"

func main() {
    fmt.Println("Hello World")
}

I get the expected output:

Hello World

However when I try to run the following, Day3.go with go run Day3.go:

package main

import (
    "fmt"
    "os"
    "go"
)

func main() {
    file, err := os.Open("puzzleinput.txt")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Print(file)
}

I get the following error message:

Day3.go:6:2: no Go files in /usr/lib/go/src/go

I also get this error message when trying to use go get and go build. Here's the result of go env (Go is installed under /usr/lib/go):

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ulrich/.cache/go-build"
GOENV="/home/ulrich/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ulrich/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build204360782=/tmp/go-build -gno-record-gcc-switches"

I've also tried uninstalling and reinstalling go, and reconfiguring my GOPATH and GOROOT environment variables to no avail. How can I fix this?

like image 785
Mahler Avatar asked Dec 05 '19 05:12

Mahler


1 Answers

Don't import the go module. It's not a package:

enter image description here

like image 125
Lucas Katayama Avatar answered Nov 09 '22 10:11

Lucas Katayama