Let's `go` in the right direction
My goal is to keep my $HOME as clean as possible!
What I’m saying is to have the minimum folder and files scattered in the $HOME directory. Today, I have …
> ls -l | wc -l
58
It is not a good number … for me. There is no correct number; find what works with you!
Today, I’m going to get rid of the go folder! I was even admired to find it is not hidden.
1. Why this folder came to here?
According to its documentation:
The go command and the tools it invokes consult environment variables for configuration. If an environment variable is unset or empty, the go command uses a sensible default setting.
Let’s see what are the “sensible default” settings:
> go env
GOCACHE="/home/.../.cache/go-build"
GOENV="/home/.../.config/go/env"
GOMODCACHE="/home/.../go/pkg/mod"
GOPATH="/home/.../go"
GOROOT="/usr/lib/golang"
GOTMPDIR=""
GOVERSION="go1.20.11"
Some this information we can get from other commands, like:
> go version
go version go1.20.11 linux/amd64
> go env GOENV
/home/.../.config/go/env
2. How can we change the defaults?
The documentation and the output above shows we have a configuration file in .config/go folder. Let’s investigate it!
There is no env file nor go folder in .config …
Well, we can change some specific environment variable with this command:
go env -w <NAME>=<VALUE>
But be aware of this catch, as documentation states:
The location of the configuration file can be changed by setting the environment variable GOENV, and ‘go env GOENV’ prints the effective location, but ‘go env -w’ cannot change the default location. See ‘go help env’ for details.
Let’s try this instead: go env -w GOPRIVATE="test"
Now, see again if there is a file. If there is, congratulations!
Also, the file is written in INI schema.
3. Now, what we change?
The following steps, you can do with the
dotbotprogram. Learn more about it in a next post.
Now open the env file with your preferred editor (mine is nano :P). Copy and paste this code, adjusting the paths:
GOENV="/home/.../.config/go/env"
GOMODCACHE="/home/.../.config/go/pkg/mod"
GOPATH="/home/.../.config/go"
GOTMPDIR="/home/.../.config/go/tmp/"
GOWORK="auto"
Adjust other variables according your needs. See them here.
Now we have another configuration folder in the correct place.
See you in the next cleanup!