Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go : go get $GOPATH error, when GOPATH is set

When running the go get command :

sudo go get github.com/go-sql-driver/mysql

I get the following error

package github.com/go-sql-driver/mysql: cannot download, $GOPATH not set. For more details see: go help gopath

However $GOPATH is already set.

Running echo $GOPATH gives /Users/userxyz/Desktop/Code

Running go env gives

.....

GOPATH="/Users/userxyz/Desktop/Code"

...

GOROOT="/usr/local/go"

.....

I have already tried setting GOPATH as an environment variable by adding the following lines

export GOPATH="$HOME/Desktop/Code"
export PATH=$PATH:$GOPATH/bin

to the following files, alternatively

~/.profile (/etc/profile)
~/.bashrc
~/.bash_profile
like image 538
John S Perayil Avatar asked Feb 13 '23 12:02

John S Perayil


1 Answers

sudo go get github.com/go-sql-driver/mysql

This runs go get under root user, which does not have $GOPATH set.

Just do:

go get github.com/go-sql-driver/mysql

Generally, do:

go get

in the project folder, and it will install all dependencies. The following will install dependencies mentioned in tests:

go get -t
like image 108
warvariuc Avatar answered Feb 15 '23 00:02

warvariuc