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
+23.9k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+10.1k Swift : Convert (cast) String to Integer
+7.2k Golang : Command line ticker to show work in progress
+4.5k JQuery : Calling a function inside Jquery(document) block
+12.6k Swift : Convert (cast) Int to String ?
+17k Golang : Clone with pointer and modify value
+5.6k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+17.9k Golang : Get path name to current directory or folder
+5.9k Golang : Detect face in uploaded photo like GPlus
+17.5k Golang : Get all upper case or lower case characters from string example
+7.1k Javascript : Push notifications to browser with Push.js
+8.4k Golang : Executing and evaluating nested loop in html template