If you search golang import local package, go import local package, golang how to import local package, import local package golang, or go local import, you are usually wiring a module path in an import block to a directory under your project. Golang import package from another directory and golang local package are the same idea: the import string is your/module/path plus /subdir for each package folder. Golang import local file is a common misconception—Go does not import single files across packages. Golang use local package and go get local package come up when you add a sibling library or a vendored path; modules handle that with replace or a single repo layout. For packaging concepts, see golang packaging; for GOPATH-era layout, see GOPATH vs GOROOT (today’s default workflow is modules, not src/workspace/...).
Tested with Go 1.24 on Linux.
One module, several packages (recommended layout)
Create a module and directories:
mkdir -p myapp/lib myapp/lib/extra
cd myapp
go mod init example.com/myappTypical tree:
myapp/
go.mod # module example.com/myapp
main.go # package main
lib/
hello.go # package lib
lib/extra/
more.go # package extrago.mod starts with the module line (a go toolchain line is added by go mod init for your installed version):
module example.com/myappgolang import local package: the import path
Every import string starts with the module path from go.mod, then continues with the subdirectories that hold the package (without repeating the module folder name on disk). From main.go:
package main
import (
"example.com/myapp/lib"
"example.com/myapp/lib/extra"
)
func main() {
lib.Hello()
extra.More()
}lib/hello.go:
package lib
import "fmt"
func Hello() {
fmt.Println("from lib")
}lib/extra/more.go:
package extra
import "fmt"
func More() {
fmt.Println("from lib/extra")
}Run go run . from myapp/; output lists both lines. That is the idiomatic answer to golang import package from another directory: the directory lib/extra maps to import path example.com/myapp/lib/extra.
Exports: why golang use local package can fail
Only capitalized names are visible outside the package. If lib defined func hello() (lowercase), main could not call lib.hello()—the compiler reports undefined. This matches the language spec for exported identifiers.
go get local package and replace (outside the tree)
If a second module lives next to your app, point to it from go.mod:
replace example.com/other => ../otherThen require example.com/other v0.0.0 and go mod tidy lets import "example.com/other/pkg" resolve to ../other/pkg on disk. That is the usual answer when people say go get local package for a path that is not published to a proxy.
Summary
Golang import local package in 2026 means: run go mod init, put each package in its own directory, and import module/path/subdir. Go import local package and golang local package searches are satisfied by that mapping—there is no parallel GOPATH src/workspace layout required. Golang import local file is not a separate mechanism: you always import a package directory. Golang import package from another directory is just a longer import path under the same module. go get local package matters when another module is on disk; use a replace directive to teach the toolchain where it lives, and remember exported names so golang use local package compiles.
References
Frequently Asked Questions
1. How do I golang import local package or go import local package today?
go mod init module/path), put each package in its own directory with a matching package clause, then import with import "module/path/subdir"—the string is the module path plus the subdirectory holding that package.2. Can I golang import local file without a folder?
.go files. Put the file in a directory and use the directory’s package name and module import path.3. What does golang import package from another directory mean in modules?
.go files with the same package name becomes an import path module/path/to/dir if the files belong to one package, or split into multiple packages in nested dirs as needed.4. How is go get local package used with a local library?
go get yourself; use import. For a separate folder outside the module, add a replace directive in go.mod pointing at a relative or absolute path, then go get / go mod tidy resolves it.
