How to install Go on Ubuntu 22.04
- 00:48 lsb_release -a
- 01:04 apt update
- 01:50 wget https://go.dev/dl/go1.21.4.linux-amd64.tar.gz -O go.tar.gz
- 02:25 tar -xzvf go.tar.gz -C /usr/local
- 03:42 echo export PATH=$HOME/go/bin:/usr/local/go/bin:$PATH >> ~/.profile
- 03:59 source ~/.profile
- 04:12 go version
- 04:32 vim demo.go
- 05:01 go run demo.go
To Install Go On Ubuntu 22.04
Introduction:
Go was originally built for programs related to networking and infrastructure. It was intended to replace popular high-performance server-side languages like Java and C++. Today, Go is used for a variety of applications like cloud and server-side applications, DevOps, command line tools, and much more.
Procedure :
Step – 1: Check the OS version by using the below command
root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy
Step – 2 : Before installation, need to update the repository by using the below command
root@linuxhelp:~# apt update
Hit:1 http://in.archive.ubuntu.com/ubuntu jammy InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:3 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:4 http://in.archive.ubuntu.com/ubuntu jammy-backports InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
255 packages can be upgraded. Run 'apt list --upgradable' to see them.
Step – 3 : Download Go by using wget command
root@linuxhelp:~# wget https://go.dev/dl/go1.21.4.linux-amd64.tar.gz -O go.tar.gz
--2024-03-21 13:30:54-- https://go.dev/dl/go1.21.4.linux-amd64.tar.gz
Resolving go.dev (go.dev)... 216.239.32.21, 216.239.38.21, 216.239.36.21, ...
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.4.linux-amd64.tar.gz [following]
--2024-03-21 13:30:54-- https://dl.google.com/go/go1.21.4.linux-amd64.tar.gz
Resolving dl.google.com (dl.google.com)... 172.217.160.142, 2404:6800:4007:81a::200e
Connecting to dl.google.com (dl.google.com)|172.217.160.142|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 66615271 (64M) [application/x-gzip]
Saving to: ‘go.tar.gz’
go.tar.gz 100%[===========================================================>] 63.53M 10.3MB/s in 6.2s
2024-03-21 13:31:01 (10.2 MB/s) - ‘go.tar.gz’ saved [66615271/66615271]
Step – 4 : Extract the downloaded file in the /usr/local location by using the below command
root@linuxhelp:~# tar -xzvf go.tar.gz -C /usr/local
go/test/typeparam/typeswitch7.go
go/test/typeparam/typeswitch7.out
go/test/typeparam/valimp.dir/
go/test/typeparam/valimp.dir/a.go
go/test/typeparam/valimp.dir/main.go
go/test/typeparam/valimp.go
go/test/typeparam/value.go
go/test/typeswitch.go
go/test/typeswitch1.go
go/test/typeswitch2.go
go/test/typeswitch2b.go
go/test/typeswitch3.go
go/test/uintptrescapes.dir/
go/test/uintptrescapes.dir/a.go
go/test/uintptrescapes.dir/main.go
go/test/uintptrescapes.go
go/test/uintptrescapes2.go
go/test/uintptrescapes3.go
Step – 5 : Set the path of Go executables in the ~/.profile, by using the below command
root@linuxhelp:~# echo export PATH=$HOME/go/bin:/usr/local/go/bin:$PATH >> ~/.profile
Step – 6 : Then, save the changes by sourcing the file by using the below command
root@linuxhelp:~# source ~/.profile
Step – 7 : Check the version of Go by using the below command
root@linuxhelp:~# go version
go version go1.21.4 linux/amd64
Step – 8 : create a simple Go program by using vim editor
root@linuxhelp:~# vim demo.go
copy the following code in the file
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
Step – 9 : Run the program by using the below command
root@linuxhelp:~# go run demo.go
Hello, World!
Conclusion :
We have reached the end of this article. In this guide, we have walked you through the steps required to installation of Go on Ubuntu 22.04. Your feedback is much welcome.
Comments ( 0 )
No comments available