Since go versions keep moving up, maintaining GOPATH inside a Go installation path is a pain.
ls /home/a-user/go/1.14.0/src bitbucket.org github.com go.uber.org golang.org gopkg.in
Adding multiple directories in GOPATH
- Create a directory e.g. for work
- GOPATH assumes a structure in the directory, so create three directories inside.
ls $HOME/mywork bin pkg src
- You will do all your personal development work inside
ls $HOME/mywork/src project-01
- Append .bashrc or .zshrc (append is a must, it won’t work otherwise because GOPATH is preset by goenv)
# keep it at the end of the file export GOENV_ROOT="$HOME/.goenv" export PATH="$GOENV_ROOT/bin:$PATH" eval "$(goenv init -)" export PATH="$GOROOT/bin:$PATH" export PATH="$PATH:$GOPATH/bin" export PATH="$PATH:$HOME/bin" # add personal directory export GOPATH="$GOPATH:$HOME/mywork/"
- Open the directory
$HOME/mywork/src/project-01in VSCode workspace.
- If you have the VSCode extension for Go installed, restart VSCode.
If go to implementation doesn’t work, ensure that go is installed properly with src directory.
bin pkg src
That’s all folks!