Last active
August 24, 2022 04:53
-
-
Save kimpepper/137f1317a6461ccfe1f1057ba8c04221 to your computer and use it in GitHub Desktop.
Install multiple versions of go with ubuntu update-alternatives
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
sudo apt install golang | |
# Set the latest default version to the highest priority. | |
sudo update-alternatives --install /usr/bin/go go /usr/lib/go/bin/go 20 \ | |
--slave /usr/bin/gofmt gofmt /usr/lib/go/bin/gofmt | |
# Install previous versions at lower priority. | |
for version in "1.17" "1.18" | |
do | |
sudo apt install golang-${version} | |
sudo update-alternatives --install /usr/bin/go go /usr/lib/go-${version}/bin/go 10 \ | |
--slave /usr/bin/gofmt gofmt /usr/lib/go-${version}/bin/gofmt | |
done | |
# Install go v1.10 from tarball into /usr/local/lib | |
version=1.19 | |
curl -sSL https://go.dev/dl/go${version}.linux-amd64.tar.gz -O | |
tar xf go${version}.linux-amd64.tar.gz | |
rm go${version}.linux-amd64.tar.gz | |
sudo mv go /usr/local/lib/go-${version} | |
sudo update-alternatives --install /usr/bin/go go /usr/local/lib/go-${version}/bin/go 30 \ | |
--slave /usr/bin/gofmt gofmt /usr/local/lib/go-${version}/bin/gofmt | |
# Set 1.18 as default | |
sudo update-alternatives --set go /usr/local/lib/go-${version}/bin/go |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Change versions with
sudo update-alternatives --config go