![]() ![]() Ii golang-src 2:1-5 Go programming language compiler - source files Ii golang-go 2:1-5 Go programming language compiler Here is an example from a Ubuntu 12.04 system which ships with Go 1.0. ![]() The binary distributions you download from the website, or install from your operating system distribution also have the correct $GOROOT value embedded into the go tool binary. You can see this when you run go env % echo $GOROOT When you compile Go from source, the value of $GOROOT is automatically discovered 2 (it is one directory up from the all.bash script) and then embedded into the go tool built from that source tree. If you are a Java user, $GOROOT is similar in effect to $JAVA_HOME. In the old Makefile based build system, it was used as the base path for including other Makefiles, and since Go 1.0 it is used by the go tool to find the compiler (stored in $GOROOT/pkg/tool/$GOOS_$GOARCH) and the standard library (also in $GOROOT/pkg/$GOOS_$GOARCH). $GOROOT has always been defined as a pointer to the root of your Go installation. Okay, so I don’t need $GOOS or $GOARCH, but what about $GOROOT ? But in case you don’t, this is documented on the website, and in this screencast. If you’ve read this far, you probably know what a $GOPATH workspace is. Go 1.0 also introduced $GOPATH based workspaces. They are now only used when cross compiling. With the release of Go 1.0, and the introduction of the cmd/dist bootstrap build tool, $GOOS and $GOARCH became truly optional. These were required because the Makefile based build system used lots of includes which used $GOROOT as their base path.īy the time the go tool was introduced, prior to Go 1.0, $GOOS and $GOARCH were optional as the build scripts were able to detect the host’s operating system and cpu architecture. Go old timers may remember when not only $GOROOT, but $GOOS and $GOARCH were required environment variables. ![]() The history of the GO* environment variables Since Go 1.0 setting $GOPATH has been highly recommended, and with the release of Go 1.1, it is considered mandatory. In fact, setting $GOROOT can lead to hard to debug problems if you have multiple versions of Go present on your computer. In general 1 it is not necessary to set the $GOROOT environment variable when compiling or using Go 1.0 or later. This is a short post to explain why it is not necessary to set $GOROOT when compiling or using Go.
0 Comments
Leave a Reply. |