Download
bash
wget -c https://go.dev/dl/go1.26.0.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local
Or
bash
sudo tar -C /usr/local/ -xzf go1.26.0.linux-amd64.tar.gz
Configuration
Add the go_path variable to the configuration file
bash
sudo touch /etc/profile.d/go.sh
sudo tee /etc/profile.d/go.sh <<-'EOF'
export GOROOT=/usr/local/go
#export GOPATH=~/go
#export PATH=$PATH:$GOROOT/bin:$GOPATH
export PATH=$PATH:$GOROOT/bin
#export GO111MODULE=on
#export GOPROXY=https://goproxy.cn,direct
EOF
Enable the ability to automatically append GOPATH at boot
bash
tee -a ~/.bashrc <<-'EOF'
if [ -f /etc/profile.d/go.sh ]; then
. /etc/profile.d/go.sh
fi
EOF
Make environment variables take effect
bash
source .bashrc
Verification
Verification results
bash
lwk@qwfys:~$ echo $GOPATH
lwk@qwfys:~$ echo $GOROOT
/usr/local/go
lwk@qwfys:~$ go version
go version go1.26.0 linux/amd64
lwk@qwfys:~$ go env
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/lwk/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/lwk/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3874236230=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/lwk/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/lwk/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/lwk/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.26.0'
GOWORK=''
PKG_CONFIG='pkg-config'
lwk@qwfys:~$