I am trying to do a go get
:
go get github.com/go-sql-driver/mysql
and it fails with the following error:
packa
go path could be every where you want just create a directory and set global path variable in the name of GOPATH to your environment.
mkdir ~/go
export GOPATH=~/go
go get github.com/go-sql-driver/mysql
export GOPATH=/path/desired/here
There is no need to edit any file, we can just use the command above to directly edit the Go environment variables.
Write this code in Terminal.
export GOPATH=path/to/your/gopath/directory
Note: This will reset on every new Terminal window or system restart.
To be persistent, paste the code below in your .zshrc
or .bashrc
file according to your shell. Those files in your Home Directory. It will be like below.
export PATH=path/to/some/other/place/composer/for/example
export GOPATH=path/to/your/gopath/directory
export PATH=$PATH:$GOPATH/bin
If you've setup anything that needs modification of environment variables e.g. Java, Go etc this will be very familiar.
I will assume that you have the following directory structure somewhere as your Go path:
\---[folder name]
+---bin
+---pkg
\---src
sudo nano /etc/environment
PATH=...
and go the end of it and add a colon :
after the last path then paste in your full go path
e.g. /home/user/gocode
and you're done, This should make it persistent through the system.
Ubuntu 14.04
export GOPATH=$HOME/go
Additionally you can add this string to file
$HOME/.bashrc
Since Go 1.11, you don't have to use GOPATH anymore. Simply go to your project directory and do this once:
go mod init github.com/youruser/yourrepo
If you insist on working with GOPATH then heed this:
From the documentation:
If no GOPATH is set, it is assumed to be $HOME/go on Unix systems and %USERPROFILE%\go on Windows. If you want to use a custom location as your workspace, you can set the GOPATH environment variable.