Offline Go Modules
By Tom Ratcliff
Using go mod vendor
With an existing module
- copy
go.mod
andgo.sum
files from the offline PC to the internet PC
New module
- create a folder on machine with internet access
- create a go module :
go mod init offline
Download dependencies via vendor folder
- create a
offline_modules.go
file :
touch offline_modules.go
- add the dependencies you want to download (use
_
) :
package offline_modules
import (
_ "github.com/gorilla/mux"
_ "github.com/sirupsen/logrus"
)
func main() {}
- To download dependencies, run:
go mod vendor
- the vendor folder should have new folders in it representing dependencies
Back to offline
- copy
go.mod
,go.sum
andvendor
directory to offline machine - run your go commands with the flag
-mod=vendor
like:
go run -mod=vendor main.go