Last active
October 23, 2024 12:09
-
-
Save ferdinandkeller/714d8898311ddafe762bbc7d50dfbfef to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# define installation folder | |
dest_folder="$HOME/.local/bin" | |
echo "golang will be installed at $dest_folder" | |
# get the current architecture | |
arch=$(dpkg --print-architecture) | |
echo "targeting $arch architecture" | |
# find the latest's version url | |
partial_url=$(curl -s "https://go.dev/dl/" | grep -oP "/dl/go[1-9\.]+\.linux-$arch.tar.gz" | sort -V | tail -n 1) | |
full_url="https://go.dev${partial_url}" | |
echo "downloading $full_url" | |
# download the file | |
wget -q $full_url -O /tmp/go.tar.gz | |
echo "downloading done" | |
# untar the file | |
tar -xzf /tmp/go.tar.gz -C /tmp | |
echo "decompression done" | |
# uninstall current go version | |
rm -rf $dest_folder/go | |
echo "removing older version done" | |
# replace install | |
mkdir -p $dest_folder | |
mv /tmp/go $dest_folder | |
echo "installation done" | |
# add path to $HOME/.bashrc & $HOME/.zshrc (if not already there) | |
new_path="PATH=\"$dest_folder/go/bin:\$PATH\"" | |
(cat $HOME/.bashrc | grep -xF $new_path) || printf "\n$new_path" >> $HOME/.bashrc | |
(cat $HOME/.zshrc | grep -xF $new_path) || printf "\n$new_path" >> $HOME/.zshrc | |
# source $HOME/.bashrc or $HOME/.zshrc | |
echo "please run 'source \$HOME/.bashrc' or 'source \$HOME/.zshrc' to update your environment variables." | |
# clean /tmp | |
rm /tmp/go.tar.gz | |
echo "cleaning done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I created this script because
apt
doesn't always have the latest version on ubuntu, and there is no official install script to make it easier.