How To Install Go on Ubuntu 20.04

Check Ubuntu version

First, run this command to make sure what version of Ubuntu you have:

lsb_release -a

Output example:

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
C…


This content originally appeared on DEV Community and was authored by Maria Yudina

Check Ubuntu version

First, run this command to make sure what version of Ubuntu you have:

lsb_release -a

Output example:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:    20.04
Codename:   focal

Install GoLang

Download the latest GoLang archive:

curl -OL https://golang.org/dl/go1.17.3.linux-amd64.tar.gz

Check SHA256 Checksum just in case:

sha256sum go1.17.3.linux-amd64.tar.gz

Extract everything to the usr/local directory:

sudo tar -C /usr/local -xvf go1.17.3.linux-amd64.tar.gz

Update PATH variable in ~/.profile file:

sudo nano ~/.profile

Add new row with export at the end of the ~/.profile file:

export PATH=$PATH:/usr/local/go/bin

Save the changes and exit nano editor. Now we have to refresh your profile. Run this command:

source ~/.profile

Installation and setup is done. Let's check if everything works.

Make sure everything works

We will check Go version and create and run a simple program.

Check the version

Run this command to check Go version:

go version

Output:

go version go1.17.3 linux/amd64

Create and run 'Hello, World!'

Let's create a simple Go program and run it.

Create a directory and switch to it.

mkdir hello_go
cd hello_go

Now we have to create go.mod file with the go mod init command:

go mod init test/hello_go

Create a file where we'll write the program code in Go.

nano hello.go

Copy this example code to the file and save changes.

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

Save the changes and exit nano editor.

Run the program:

go run .

Output:

Hello, World!

Done!


This content originally appeared on DEV Community and was authored by Maria Yudina


Print Share Comment Cite Upload Translate Updates
APA

Maria Yudina | Sciencx (2021-11-06T19:52:36+00:00) How To Install Go on Ubuntu 20.04. Retrieved from https://www.scien.cx/2021/11/06/how-to-install-go-on-ubuntu-20-04/

MLA
" » How To Install Go on Ubuntu 20.04." Maria Yudina | Sciencx - Saturday November 6, 2021, https://www.scien.cx/2021/11/06/how-to-install-go-on-ubuntu-20-04/
HARVARD
Maria Yudina | Sciencx Saturday November 6, 2021 » How To Install Go on Ubuntu 20.04., viewed ,<https://www.scien.cx/2021/11/06/how-to-install-go-on-ubuntu-20-04/>
VANCOUVER
Maria Yudina | Sciencx - » How To Install Go on Ubuntu 20.04. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/06/how-to-install-go-on-ubuntu-20-04/
CHICAGO
" » How To Install Go on Ubuntu 20.04." Maria Yudina | Sciencx - Accessed . https://www.scien.cx/2021/11/06/how-to-install-go-on-ubuntu-20-04/
IEEE
" » How To Install Go on Ubuntu 20.04." Maria Yudina | Sciencx [Online]. Available: https://www.scien.cx/2021/11/06/how-to-install-go-on-ubuntu-20-04/. [Accessed: ]
rf:citation
» How To Install Go on Ubuntu 20.04 | Maria Yudina | Sciencx | https://www.scien.cx/2021/11/06/how-to-install-go-on-ubuntu-20-04/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.