Table of Contents
In today's post, we will talk about how to upgrade Go version on your computer. As mentioned on the official page, if you want to update go version, you first need to uninstall the original version.
Update Go on Debian/Ubuntu/Fedora Linux
Step-1: Uninstall the existing version
To uninstall go, you have to locate where Go is on your system (locate the program file in the user path)
which go
To make sure, you can run the command to find the Go source location:
where go
To uninstall, delete the /usr/local/go
directory or the source directory which you have received as output in previous command with root user using the following command:
sudo rm -rf /usr/local/go
To check if you already remove go, run the below command; the system will prompt "command go not found"
go --version
Step-2: Install the new version
Go to the downloads page and download the version release which suitable for your system. You can read more at Getting started with GOLANG
To extract the archive file (remember to change the downloaded file's path )
sudo tar -C /usr/local -xzf /home/golinuxcloud/Downloads/go1.19.3.linux-amd64.tar.gz
/usr/local/go/bin
export PATH=$PATH:/usr/local/go/bin
After that, you will need to restart your terminal for the change to take effect.
To check if you have installed Go successfully, run the below command. Confirm that the command prints the installed version of Go.
go --version
Update Go on Windows
Step-1: Uninstall the existing version
Go can be easily uninstalled using Add/Remove Programs in the Windows control panel:
1. Go to the Control Panel section, and double-click Add/Remove Programs.
2. In Add/Remove Programs, right-click the go version you want to uninstall (for example Go Programming Language amd64 go1.19.3) then follow the prompts.
3. Click Yes to confirm uninstall Go
Step-2: Install the new version
Go download: go to the download page and choose your version
Open the MSI file you downloaded and follow the prompts to install Go. By default, the installer will install Go to Program Files
 or Program Files (x86)
. You can change the location as per your environment. After installing, you will need to close and reopen any open command prompts so that changes to the environment made by the installer are reflected in the command prompt.
To check if you have installed Go successfully, run the below command. Confirm that the command prints the installed version of Go.
go --version
Upgrade using Chocolatey [Optional]
Chocolatey has the largest online registry of Windows packages. Chocolatey packages encapsulate everything required to manage a particular piece of software into one deployment artifact by wrapping installers, executables, zips, and/or scripts into a compiled package file. Go can also be updated using the Chocolatey package manager. Run from an elevated shell to minimize the risk of installation issues.
Install using:
choco install golang -y
Update using:
choco upgrade golang -y
Update Go on MacOS
Step-1: Uninstall the existing version
If you have used an installer, you can uninstall Go by using the same installer. If you have installed it from the source then rm -rf /usr/local/go
rm -rf $(echo $GOPATH)
Then, remove all entries related to go i.e. GOROOT, GOPATH from ~/.bash_profile
 and run
source ~/.bash_profile
If you installed Go with the macOS package, remove the /etc/paths.d/go
 file.
Step-2: Install the new version
Open the package file you downloaded and follow the prompts to install Go.
The package installs the Go distribution to /usr/local/go. The package should put the /usr/local/go/bin directory in your PATH
 environment variable. You may need to restart any open Terminal sessions for the change to take effect.
Verify that you've installed Go by opening a command prompt and typing the following command. Confirm that the command prints the installed version of Go.
go version
Summary
Your Go is successfully updated. To update it you need to remove your existing go folder, then reinstall the newest version. Remember that we can use multiple versions of Golang on a computer.
References
https://go.dev/doc/install#install
https://go.dev/dl/