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
+3.9k JQuery : Calling a function inside Jquery(document) block
+8.2k Golang : Temperatures conversion example
+17.4k Golang : Set, Get and List environment variables
+4.4k Python : Delay with time.sleep() function example
+16.2k Golang : Linked list example
+4.8k Golang : Denco multiplexer example
+10.6k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+9.7k Golang : Fix - does not implement sort.Interface (missing Len method)
+7.5k Golang : Progress bar with ∎ character
+18.2k Golang : Measure http.Get() execution time
+4.8k Cash Flow : 50 days to pay your credit card debt
+6.5k SSL : How to check if current certificate is sha1 or sha2 from command line