While executing main.go occurring error: package XX is not in GOROOT (/usr/lib/go/src/XX)

Viewed 20

I'm new to go. I was trying to learn importing from packages, my folder structure is like-

GO
├── bin
├── pkg
└── src
    ├── cur
    │   └── main.go
    └── greet
        └── day.go

main.go :-

package main

import (
    "fmt"
    "greet"
)
func main() {
    fmt.Println(greet.Morning)
}

day.go :-

package greet

var Morning = "Working from greet package"

It's throwing the error ("package greet is not in GOROOT (/usr/local/go/src/greet)") whenever I try to build, install or run. I'm following this tutorial.

How can I get rid of it? I've already tried this solution, but not working.

go env :-

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/abir/.cache/go-build"
GOENV="/home/abir/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/abir/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/abir/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build210239449=/tmp/go-build -gno-record-gcc-switches"
0 Answers
Related