Advertisement
Justman10000

Manage Go

Feb 25th, 2023 (edited)
1,047
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.11 KB | None | 0 0
  1. // To install go
  2. version=$(curl -s https://go.dev/dl/ | grep -oP 'go([0-9]+(\.[0-9]+)+)\.linux-amd64\.tar\.gz' | sort -rV | head -n 1 | grep -oP '[0-9]+\.[0-9]+\.[0-9]+')
  3. # rcVersion=$(curl -s https://go.dev/dl/ | grep -oP 'go[0-9]+\.[0-9]+rc[0-9]+\.linux-amd64\.tar\.gz' | sort -rV | head -n 1 | grep -oP -i '[0-9]+\.[0-9]+rc[0-9]+')
  4.  
  5. # Download, unpack and install go
  6. wget https://go.dev/dl/go$version.linux-amd64.tar.gz
  7. gunzip go$version.linux-amd64.tar.gz
  8. tar xvf go$version.linux-amd64.tar
  9. mv go /usr/local
  10. ln -s /usr/local/go/bin/* /usr/bin
  11. rm -r go$version.linux-amd64.tar
  12.  
  13. # Set envs
  14. export GOPATH=/usr/local/go
  15. export GOCACHE=/usr/local/go/cache
  16.  
  17. # Re-Register go bins
  18. for bin in $(ls /usr/local/go/bin)
  19. do
  20. [ -f /usr/bin/$bin ] && rm -r /usr/bin/$bin
  21. [ ! -f /usr/bin/$bin ] && ln -s /usr/local/go/bin/$bin /usr/bin
  22. done
  23.  
  24. # Check version, to see, if go installed
  25. go version
  26.  
  27. # To register all binarys all go packages (new)
  28. for bin in $(ls /root/go/bin)
  29. do
  30. [ -f /usr/bin/$bin ] && rm -r /usr/bin/$bin
  31. ln -s /root/go/bin/$bin /usr/bin
  32. done
  33.  
  34. // To uninstall go
  35. rm -r /usr/local/go
  36. rm -r /usr/bin/go*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement