How to install latest version of golang(go) in linux

How to Install latest version of Golang(Go) in Linux

In this article we will see how to install latest version of Golang(Go) in Linux. Golang or Go is a free and open source programming language developed by Google. It was designed by Robert Griesemer, Rob Pike, and Ken Thompson and officially released in 2009. Golang is known for its simplicity, efficiency, and strong support for concurrent programming. For Golang based applications to work in your system, it is required to have Golang pre installed in your system. In many cases, applications require latest version of GO in your system to be able to work properly.

If you have the older version installed then the probably you have to either remove them and install the latest one or upgrade the current version to the latest one. Here we will see how you can install the latest version of Golang in Linux by following few simple steps.

Sponsored

 

Key Features

a) Simplicity and Clarity: Go’s syntax is clean and concise. It was designed to be easy to read and write, minimizing the unnecessary complexities often found in other languages.

b) Compiled Language: Go compiles to machine code, which means Go programs run directly on the underlying hardware without the need for an interpreter. This results in fast execution and efficient use of system resources.

c) Strong Concurrency Support: One of Go’s standout features is its built-in support for concurrent programming. It introduces ‘goroutines’, lightweight threads managed by the Go runtime, and ‘channels’, for communication between goroutines. This makes it easier to build applications that perform multiple operations simultaneously.

d) Static Typing: Go is statically typed, which means that variable types are explicitly declared and checked at compile time. This can help catch errors early in the development process.

e) Garbage Collected: Go has a built-in garbage collector which automatically deallocates memory that is no longer in use, helping prevent memory leaks and other related issues.

f) Standard Library: Go comes with a rich standard library that offers a wide range of functionalities, from handling I/O operations and building HTTP servers to manipulating strings and dates.

g) Tooling: Go provides excellent tooling, with features like a built-in testing framework, benchmarking tools, and efficient package management.

h) Cross-Platform: Go supports cross-platform development, which means you can write code once and compile it for multiple operating systems like Windows, Linux, and macOS.

i) Strong Ecosystem: Over the years, Go has developed a strong ecosystem with a wide array of third-party libraries and tools, making it suitable for a variety of applications.

j) Use Cases: It’s widely used in cloud computing, server-side applications, distributed systems, command-line tools, and even for some types of system programming.

 

How to install latest version of golang(go) in linux

How to Install latest version of Golang(Go) in Linux

Also Read: How to Install VeraCrypt on Ubuntu 22.04

Step 1: Prerequisites

a) You should have a running Linux Server with Kernel version 2.6.32 or later.

b) You should have sudo or root access to run privileged commands.

c) You should have wget utility installed in your Server.

 

Step 2: Update Your Server

Before installing Golang in your server, it is recommended to check and install all the latest available updates to keep your server safe and secure from any potential vulnerabilities and bugs. If you are using ubuntu or debian based linux then you can update packages by running sudo apt update && sudo apt upgrade command as shown below.

Sponsored
sudo apt update && sudo apt upgrade

If you are using RHEL or CentOS or Fedora based linux then you can update packages by running either sudo yum update && sudo yum upgrade or sudo dnf update && sudo dnf upgrade command as shown below.

sudo yum update && sudo yum upgrade
sudo dnf update && sudo dnf upgrade

 

Step 3: Download Golang

You have to first download the latest Golang tarball from official website by using any of the file transfer utility such as wget or curl. For example, in our case we are using wget utility to download the tarball as shown below.

cyberithub@ubuntu:~$ wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz
--2023-12-17 12:36:39-- https://go.dev/dl/go1.21.5.linux-amd64.tar.gz
Resolving go.dev (go.dev)... 2001:4860:4802:38::15, 2001:4860:4802:34::15, 2001:4860:4802:32::15, ...
Connecting to go.dev (go.dev)|216.239.32.21|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://dl.google.com/go/go1.21.5.linux-amd64.tar.gz [following]
--2023-12-17 12:45:23-- https://dl.google.com/go/go1.21.5.linux-amd64.tar.gz
Resolving dl.google.com (dl.google.com)... 2404:6800:4009:827::200e, 142.250.199.174
Connecting to dl.google.com (dl.google.com)|2404:6800:4009:827::200e|:443... failed: Connection timed out.
Connecting to dl.google.com (dl.google.com)|142.250.199.174|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 66618285 (64M) [application/x-gzip]
Saving to: ‘go1.21.5.linux-amd64.tar.gz’

go1.21.5.linux-amd64.tar.gz 100%[============================================================================>] 63.53M 3.29MB/s in 20s

2023-12-17 12:47:54 (3.13 MB/s) - ‘go1.21.5.linux-amd64.tar.gz’ saved [66618285/66618285]

 

Also Read

 

Step 4: Install Golang

If you have any older or earlier version of Golang already installed in your system then you have to remove it before installing the latest one. You can use below command to remove the older version and install the latest version in your system.

cyberithub@ubuntu:~$ sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz

 

Also Read

 

Step 5: Export PATH

Since go binary utility won’t be directly visible to the system so you have to add the binary path in global PATH environment variable using below export command. However keep in mind that below addition is just a temporary one, to make the addition permanent you have to create an export entry in ~/.profile file and then logout and login to the system to reflect the changes.

cyberithub@ubuntu:~$ export PATH=$PATH:/usr/local/go/bin

 

Also Read

 

Step 6: Check Version

Once binary path is added, you can verify the utility by running go version command as shown below. This will show the current golang version installed in your system.

cyberithub@ubuntu:~$ go version
go version go1.21.5 linux/amd64

 

Step 7: Write a Sample Program

Now that Golang is installed in the system, let’s write a sample program and run it to test the working of Go compiler in the system. Here we are writing a simple go program hello.go which displays a message "Hi, This is from itsfosslinux.com" on the output. To compile the program, run go run hello.go command. You will see the message displayed on the output. This confirms go compiler is working as expected.

cyberithub@ubuntu:~$ nano hello.go
package main
import "fmt"
func main() {
fmt.Println("Hi, This is from itsfosslinux.com")
}

 

Output

cyberithub@ubuntu:~$ go run hello.go
Hi, This is from itsfosslinux.com


Discover more from Ubuntu-Server.com

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply