Go-1.26.1

Introduction to Go

The Go package contains a compiler for the Go language, a Google-supported, object-oriented programming language.

Modern Go is written in the Go language, thus requiring a Go compiler to compile the modern Go compiler. If Go isn't installed already, then the instructions will have you compile multiple older versions of Go, starting with one that was written in C, then compile newer versions from there.

Note

This may take a while to build. Feel free to do something else while this is building.

Bootstrapping Go

If you haven't installed Go yet, you will need to bootstrap it. GCC-Go is unsuitable as it has several issues that prevent it from being able to build Go properly. This process will build an older C version, followed by newer versions which are written fully in Go.

Note

Don't do the process in the main extracted directory.

First create a list of previous Go versions that must be downloaded and built:

cat > go-bootstrap-1.26.1 << "EOF"
ceb95ea6aef52c1fb472d3539c6ef68670778b5b/go-ceb95ea6aef52c1fb472d3539c6ef68670778b5b.tar.gz
15da892a4950a4caac987ee72c632436329f62d5/go-15da892a4950a4caac987ee72c632436329f62d5.tar.gz
90a870f1dc49bfcc6ffe95f80fbaf21875198e7a/go-90a870f1dc49bfcc6ffe95f80fbaf21875198e7a.tar.gz
5817e650946aaa0ac28956de96b3f9aa1de4b299/go-5817e650946aaa0ac28956de96b3f9aa1de4b299.tar.gz
96e4e2b1616c3c59577d48abcf2823bf1fdcd2e2/go-96e4e2b1616c3c59577d48abcf2823bf1fdcd2e2.tar.gz
EOF

Using Wget, download all the Go versions that will be used to bootstrap modern Go:

grep -v '^#' go-bootstrap-1.26.1 | wget -i- -c \
  -B https://github.com/golang/go/archive/

Start a subshell that will exit on error:

bash -e

Now bootstrap all the Go versions:

for go in $(grep -v '^#' go-bootstrap-1.26.1)
do
  go=$(basename "$go")
  godir=${go%.tar.?z*}
  echo "Bootstrapping $godir"

  rm -rf $godir
  tar -xf $go
  pushd $godir

  if [ -e src/cmd/dist/a.h ]; then
    sed -i '/typedef int bool/d' src/cmd/dist/a.h
  fi

  cd src
  CFLAGS+=" -std=gnu17" sh make.bash -v
  popd
  export GOROOT_BOOTSTRAP=$PWD/$godir
done; exit

Installation of Go

As the root user, create the directory all the Go components will be installed in:

mkdir -pv /opt/go-1.26.1

In order to build modern Go, ensure you already have Go installed or boostrapped Go.

If you bootstrapped Go, extract the main Go download and change into the extracted directory, then set a variable telling the build system where to find the bootstrapped build:

export GOROOT_BOOTSTRAP=$PWD/../go-96e4e2b1616c3c59577d48abcf2823bf1fdcd2e2

Install Go by running the following commands:

cd src &&
CGO_ENABLED=1 GOROOT_FINAL=/opt/go-1.26.1 sh make.bash -v

Now, as the root user:

ln -sfvn go-1.26.1 /opt/go &&
for i in ../{bin,pkg,src,lib,misc,api,test}; do
  cp -va $i /opt/go-1.26.1
done &&
ln -svf  /opt/go/bin/go    /usr/bin &&
ln -svf  /opt/go/bin/gofmt /usr/bin &&
install  -vDm644 ../go.env \
         -t /opt/go-1.26.1/ &&

rm -rf /opt/go-1.26.1/pkg/bootstrap    &&
rm -rf /opt/go-1.26.1/pkg/obj/go-build &&
cp -va ../doc /usr/share/doc/go-1.26.1

Unset previously set variables:

unset GOROOT_BOOTSTRAP

Contents

Installed Programs: go and gofmt
Installed Libraries: None
Installed Directories: /opt/go{,-1.26.1}

Short Descriptions

go

is the modern Go compiler

gofmt

formats Go code