• Installation de Go
$ #Télécharger la release pour son architecture (ici linux / amd64)
$ cd $HOME
$ wget https://go.dev/dl/go1.20.linux-amd64.tar.gz

$ #Décompresser l'archive et l'installer dans $HOME/go-release
$ tar xvfz go.*tar.gz (Un sous répertoire go sera créé)
$ cd $HOME

$ #Définir le chemin vers l'installation de GO 
$ export GOROOT=$HOME/go

$ #Définir la variable GOPATH (emplacement des librairies externes)
$ mkdir -p $HOME/gopath
$ export GOPATH=$HOME/gopath

$ #Ajouter les binaires GO dans le path
$ export PATH=$HOME/go/bin:$PATH

https://pkg.go.dev/cmd/go#hdr-Environment_variables

$GOROOT
	The GOROOT directory for the 'go' command that invoked the
	generator, containing the Go toolchain and standard library.

$PATH
	The $PATH of the parent process, with $GOROOT/bin
	placed at the beginning. This causes generators
	that execute 'go' commands to use the same 'go'
	as the parent 'go generate' command.

    The Go path is used to resolve import statements. It is implemented by and documented in the go/build package.

Ma configuration:

$ cat ~/.bashrc
export GOROOT="/home/olivier/go"
export GOPATH="/home/olivier/gopath"
export PATH=$GOROOT/bin:$PATH



$ go env 2>&1 | grep -Ei "GOROOT|GOPATH"
GOPATH='/home/olivier/go-path'
GOROOT='/home/olivier/go-release'

  • Compilation Hello World

$vim tmp/test.go

package main

func main(){
	println("Hello world")
}

$ go build test.go
$ ./test.go
Hello

  • Proxies et vérifications TLS

Dans certains cas (réseau sécurisé d'entreprise avec proxies), il peut être nécessaire de définir des proxies ou de désactiver les vérifications SSL.

Ce contournement est bien sur déconseillé ...

$ // Déclaration d'un proxy
$ export http_proxy="http://yourproxy:port"
$ export https_proxy="http://yourproxy:port"

$ // Désactivation des vérifications SSL
$ export GOINSECURE="proxy.golang.org/*,golang.org/*,github.com,github.com/*"