'should I still declare GOPATH?

  • I WAS reading Learning GO and suggest that needs to be declared on PATH GOPATH="/home/user/go".

this is from author:

it’s a good idea to explicitly define GOPATH and to put the $GOPATH/bin directory in your executable path. Explicitly defining GOPATH makes it clear where your Go workspace is located and adding $GOPATH/bin to your executable path makes it easier to run third-party tools installed via go install.

  • when I run go env 1.18.1, is already declared, so why still suggesting declaring inside your path in .bashrc or .bash_profile

thanks



Solution 1:[1]

[S]hould I still declare GOPATH, GOROOT?

No and NO!

GOPATH defaults to $HOME/go which is fine and GOPATH based builds are deprecated since several years. Use modules.

GOROOT never was a thing for the enduser of Go. You have to set if you work on the Go compiler itself or install Go in unusual location (which no enduser should do).

Keep away from any resource wich promotes GOPATH or even advises to mess with GOROOT.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JimB