Why can I not install external packages?

95 views
Skip to first unread message

Tenjin

unread,
Apr 13, 2021, 5:40:12 AM4/13/21
to golang-nuts
So I am using WSL2 to develop using golang but for some reason I am unable to use other peoples packages.
For example: I am wanting to use the sql driver https://github.com/go-sql-driver/mysql I am able to go get it and it says it is downloading then it downloads but when I go to use it in my project it just says there is no go mod file, so I was going to use that to manage packages but when I run "go init" it just says initializing git repo and then does not create a go mod file.
I do not mind which way I have to use to get the driver working I just need to get it working. One more thing, I cannot install any packages its not just the sql driver.

Here is my gopath: /home/<username>/go

Brian Candler

unread,
Apr 13, 2021, 5:56:26 AM4/13/21
to golang-nuts
... Try the following:

mkdir myprog
cd myprog
go mod init myprog
... now use your editor to create main.go which references some third-party package, here is a minimal example:
--------------
package main

func main() {
}
--------------
... then:

go mod tidy
go build .

Jan Mercl

unread,
Apr 13, 2021, 5:57:22 AM4/13/21
to Tenjin, golang-nuts
In your module directory:

$ go mod init example.com/foo/bar
$ go mod tidy
$ GO111MODULE=on go build -v -x

The last line just verifies if it works and should possibly reveal why, if not.

> Here is my gopath: /home/<username>/go

In your setup the value of $GOPATH should not matter.

Tenjin

unread,
Apr 13, 2021, 6:21:18 AM4/13/21
to golang-nuts
There we go!
It is now working thanks alot guys.

Reply all
Reply to author
Forward
0 new messages