atc0005 / notes

Various notes, quick references and topics I want to explore further
MIT License
0 stars 0 forks source link

Go | multiple versions installation #60

Open atc0005 opened 2 years ago

atc0005 commented 2 years ago

Overview

Go supports installing/using multiple versions of the toolchain. Visual Studio Code + the Go plugin allows for selecting the desired Go version from the list of installed toolchains.

References

atc0005 commented 2 years ago

What follows is what I did to:

  1. remove a Go 1.17.x installation
  2. install the latest Go 1.18 version
  3. install the latest 1.19 and 1.17 versions as alternate installs
atc0005 commented 2 years ago

In particular, I had to comment out the GOROOT environment variable in $HOME/.profile. Leaving this set to /usr/local/go blocked me from being able to switch between Go versions in Visual Studio Code.

My workaround from the bottom of $HOME/.profile:

# https://www.digitalocean.com/community/tutorials/how-to-install-go-and-set-up-a-local-programming-environment-on-ubuntu-18-04

# Where Go projects live
export GOPATH="$HOME/go"

# Path of downloaded/extracted tarball from upstream
#
# NOTE: Do not set this if you wish to use multiple Go versions
# (e.g., from vscode's version switcher functionality)
#
#export GOROOT="/usr/local/go"
export DEFAULT_GOROOT="/usr/local/go"

# https://golang.org/doc/install
#export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
export PATH=$PATH:$GOPATH/bin:$DEFAULT_GOROOT/bin

# Remind me which WSL environment I'm using
lsb_release -d | awk -F ':' '{ print $2 }' | sed -r 's/^\s+//'
atc0005 commented 2 years ago
$ sudo rm -rf /usr/local/go

$ wget http://192.168.236.1:8080/installers/go1.18.5.linux-amd64.tar.gz
--2022-08-12 06:25:39--  http://192.168.236.1:8080/installers/go1.18.5.linux-amd64.tar.gz
Connecting to 192.168.236.1:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 141855946 (135M) [application/gzip]
Saving to: ‘go1.18.5.linux-amd64.tar.gz’

go1.18.5.linux-amd64.tar.gz                          100%[===================================================================================================================>] 135.28M   130MB/s    in 1.0s

2022-08-12 06:25:40 (130 MB/s) - ‘go1.18.5.linux-amd64.tar.gz’ saved [141855946/141855946]

$ sudo tar zxf go1.18.5.linux-amd64.tar.gz -C /usr/local/

$ go version
go version go1.18.5 linux/amd64

$ go install golang.org/dl/go1.19@latest
go: downloading golang.org/dl v0.0.0-20220802161245-b76e4016dde5

$ go1.19 download
Downloaded   0.0% (    16384 / 148796421 bytes) ...
Downloaded   0.0% (    49152 / 148796421 bytes) ...
Downloaded   7.8% ( 11583408 / 148796421 bytes) ...
Downloaded  15.6% ( 23199568 / 148796421 bytes) ...
Downloaded  23.5% ( 34930432 / 148796421 bytes) ...
Downloaded  31.3% ( 46546592 / 148796421 bytes) ...
Downloaded  39.1% ( 58211920 / 148796421 bytes) ...
Downloaded  45.8% ( 68222464 / 148796421 bytes) ...
Downloaded  53.7% ( 79904160 / 148796421 bytes) ...
Downloaded  61.5% ( 91569488 / 148796421 bytes) ...
Downloaded  69.4% (103234800 / 148796421 bytes) ...
Downloaded  77.2% (114883744 / 148796421 bytes) ...
Downloaded  83.4% (124157008 / 148796421 bytes) ...
Downloaded  91.3% (135838720 / 148796421 bytes) ...
Downloaded  99.1% (147471264 / 148796421 bytes) ...
Downloaded 100.0% (148796421 / 148796421 bytes)
Unpacking /home/ubuntu/sdk/go1.19/go1.19.linux-amd64.tar.gz ...
Success. You may now run 'go1.19'

$ go install golang.org/dl/go1.17.13@latest

$ go1.17.13 download
Downloaded   0.0% (    16384 / 135056550 bytes) ...
Downloaded   1.5% (  2015232 / 135056550 bytes) ...
Downloaded  10.1% ( 13696928 / 135056550 bytes) ...
Downloaded  18.8% ( 25362240 / 135056550 bytes) ...
Downloaded  27.4% ( 37027568 / 135056550 bytes) ...
Downloaded  36.1% ( 48692880 / 135056550 bytes) ...
Downloaded  43.9% ( 59293248 / 135056550 bytes) ...
Downloaded  52.3% ( 70581744 / 135056550 bytes) ...
Downloaded  60.8% ( 82132368 / 135056550 bytes) ...
Downloaded  69.5% ( 93797696 / 135056550 bytes) ...
Downloaded  78.1% (105479392 / 135056550 bytes) ...
Downloaded  86.7% (117144720 / 135056550 bytes) ...
Downloaded  94.3% (127351872 / 135056550 bytes) ...
Downloaded 100.0% (135056550 / 135056550 bytes)
Unpacking /home/ubuntu/sdk/go1.17.13/go1.17.13.linux-amd64.tar.gz ...
Success. You may now run 'go1.17.13'

$ ls sdk/
go1.17.13  go1.18.5  go1.19

$ go1.19 version
go version go1.19 linux/amd64

$ go1.17.13 version
go version go1.17.13 linux/amd64

$ go version
go version go1.18.5 linux/amd64
atc0005 commented 2 years ago

From https://go.dev/doc/manage-install#installing-multiple:

When you have multiple versions installed, you can discover where each is installed, look at the version's GOROOT value. For example, run a command such as the following:

$ go1.10.7 env GOROOT

To uninstall a downloaded version, just remove the directory specified by its GOROOT environment variable and the goX.Y.Z binary.

atc0005 commented 2 years ago

To prune multi-version Go 1.17.13, 1.18.5 and 1.19 installations:

atc0005 commented 2 years ago

Install latest versions:

go install golang.org/dl/go1.19.1@latest
go1.19.1 download
go1.19.1 version

go install golang.org/dl/go1.18.6@latest
go1.18.6 download
go1.18.6 version

go install golang.org/dl/go1.17.13@latest
go1.17.13 download
go1.17.13 version
atc0005 commented 1 year ago

Scratch script (e.g., Git Bash):

#!/bin/bash

current_oldstable_go_version="1.18.10"
current_stable_go_version="1.19.5"
current_unstable_go_version="1.20rc2"

echo "Removing multi-version Go installations ..."
rm $HOME/go/bin/go1.1*
rm -rf $HOME/sdk/

echo "Configuring multi-version Go environment ..."

go install golang.org/dl/go${current_oldstable_go_version}@latest
go${current_oldstable_go_version} download

go install golang.org/dl/go${current_unstable_go_version}@latest
go${current_unstable_go_version} download