In this tutorial, we will learn about how to upgrade Go version in Linux. As we know, any software upgrade is done because of many reasons. Every new version of a software comes with some or other enhancement like bug fixes and Performance improvements, Security updates, Compatibility, new features, better tooling etc. We will learn about how to upgrade Go version on CentOS 7 operating system in the upcoming section.
[Solved] How to Upgrade Go Version in Linux
Follow below steps to upgrade the Go version in CentOS 7 system. Please note, below steps may not work on other Linux distribution as steps vary on different distribution of Linux.
- CentOS 7 operating system installed
- Access to internet from system
- Non-user with sudo access/ root user access
Step-1: Check Current Go Version
In this step, check the Go version which is currently installed in your system using below command.
[root@linuxnasa ~]# go version go version go1.17.7 linux/amd64
Next, check the path where go binary is installed using below command. This path will be used to uninstall the current Go version in the next step.
[root@linuxnasa ~]# which go /usr/bin/go
Step-2: Uninstalled Current Go Version
In this step, uninstall the current Go version by removing the Go binary from the path in your system using below command.
[root@linuxnasa ~]# rm -rf /usr/bin/go
Step-3: Download New Go Archive
In this step, download the latest Go version archive using wget utility from the link go.dev
[root@linuxnasa ~]# wget https://go.dev/dl/go1.21.1.linux-amd64.tar.gz --2023-09-16 18:05:49-- https://go.dev/dl/go1.21.1.linux-amd64.tar.gz Resolving go.dev (go.dev)... 126.96.36.199, 188.8.131.52, 184.108.40.206, ... Connecting to go.dev (go.dev)|220.127.116.11|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://dl.google.com/go/go1.21.1.linux-amd64.tar.gz [following] --2023-09-16 18:05:49-- https://dl.google.com/go/go1.21.1.linux-amd64.tar.gz Resolving dl.google.com (dl.google.com)... 18.104.22.168, 2a00:1450:4026:805::200e Connecting to dl.google.com (dl.google.com)|22.214.171.124|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 66633012 (64M) [application/x-gzip] Saving to: ‘go1.21.1.linux-amd64.tar.gz’ 100%[========================================================================================>] 66,633,012 117MB/s in 0.5s 2023-09-16 18:05:49 (117 MB/s) - ‘go1.21.1.linux-amd64.tar.gz’ saved [66633012/66633012]
Next, untar the archive and copy in /usr/local path using below command.
[root@linuxnasa ~]# tar -C /usr/local -xzf go1.21.1.linux-amd64.tar.gz
Step-4: Install New Go Version
In this step, add the new Go version binary in the PATH variable using below command.
This command is used to add the Go binary path in PATH variable for each session.
[root@linuxnasa ~]# export PATH=$PATH:/usr/local/go/bin
This command is used to add the GO binary path in PATH variable permanently.
[root@linuxnasa ~]# echo "PATH=\$PATH:/usr/local/go/bin" >> ~/.bashrc
Next, open a new session and check if Go binary path is added in the PATH variable using below command.
[root@linuxnasa ~]# echo $PATH | grep "/usr/local/go/bin" /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/go/bin:/root/bin
Step-5: Verify New Go Version
In this step, verify if new Go version is properly installed and configured in the system using below command. If it returns the new version in the output, that means new Go version is installed successfully.
[root@linuxnasa ~]# go version go version go1.21.1 linux/amd64
We have successfully upgraded the Go version on CentOS 7 system. If you are new to Go and want to download and install Go in your system you can refer to Go official documentation at go.dev.