Golang : Fix cannot download, $GOPATH not set error
For anyone exploring Golang and trying to get new packages from ... let say Github. One of the most common error message encounter by new comers is probably the cannot download, $GOPATH not set error message when attempting to execute the go get
command.
For example :
go get github.com/go-sql-driver/mysql
will produce error message such as :
package github.com/go-sql-driver/mysql: cannot download, $GOPATH not set. For more details see: go help gopath
To fix this error message :
execute
go env
command to list out the all environment variables related to Go.if
GOPATH=""
then you need to create a workspace and setGOPATH
pointing to the workspace.It is recommended to create a new empty directory to place all the downloaded codes
mkdir ~/gopath
export GOPATH=$HOME/gopath
Verify
GOPATH
is set by executinggo env
command again.GOPATH
value should not be""
.try executing
go get
command again and it should not issue cannot download, $GOPATH NOT set error again.
At this stage it should be sufficient to get things moving again. However, you might want to save this into your bashrc file or equivalent so that GOPATH environment variable will persist even after reboot.
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8.3k Golang : Routes multiplexer routing example with regular expression control
+8.4k Golang: Prevent over writing file with md5 hash
+7.1k Web : How to see your website from different countries?
+24.2k Golang : Find biggest/largest number in array
+14.7k Golang : Overwrite previous output with count down timer
+8.4k Golang : Get final or effective URL with Request.URL example
+15.7k Golang : Validate hostname
+10.8k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+10.7k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+12.4k Golang : Get month name from date example
+19.7k Golang : Close channel after ticker stopped example
+11.7k Golang : Simple file scaning and remove virus example