Create Golang Project Folder Anywhere

Anto Haryanto
1 min readMar 26, 2020

--

Actually Golang recommends to create a project folder in one directory that has been registered in the GOPATH Environment Variable. But if for some reason we want to create a golang project in another directory, then you can register the directory temporarily in GOPATH, to do this you can use the following code, and run it in the terminal:

export GOPATH=$GOPATH:<your project path>

But because this is temporary, you must keep the terminal open, if you close it, then you must run the above command again.

Temporary GOPATH and VSCode

Because I use the vscode IDE, to make it easier, i make a file that I named “sh_open_vscode.sh” with the code as below, and put the file in the project folder anywhere, with this code:

#!/bin/sh
export GOPATH=$GOPATH:$(pwd)
code .

Then to open the IDE I just need to execute this file, vscode IDE will open, and vscode intellisense will work fine, and go build with vscode terminal will also working properly.

--

--