How to install Go on Ubuntu 20.04

This article was first published at: https://www.itcoder.tech/posts/how-to-install-go-on-ubuntu-20-04/

Go, often called golang, is a modern open source programming language created by Google that allows you to build real-time and efficient applications.

Many popular applications, such as Kubernetes, Docker, Prometheus and Terraform, are written in Go.

This tutorial explains how to download and install Go on Ubuntu 20.04.

1. Install Go on Ubuntu 20.04

Complete the following steps to install Go on Ubuntu 20.04

1.1 Download the Go zip package###

At the time of writing this article, the latest version of Go is 1.14.2. When we download the installation package, please browse Go official download page, and check if there is a new version available.

Run the following command as root or another sudo user to download and unzip the Go binary file to the /usr/local directory:

wget -c https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz -O -| sudo tar -xz -C /usr/local

1.2 Adjust environment variables###

By adding the Go directory to the $PATH environment variable, the system will know where to find the Go executable.

This can be done by adding the following line to the /etc/profile file (installed system-wide) or $HOME/.profile file (installed by the current user):

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

Save the file and reload the new PATH environment variable into the current shell session:

source ~/.profile

1.3 Verify the Go installation process###

Verify the installation process by printing the Go version number.

go version

The output should look like this:

go version go1.14.2 linux/amd64

Two, Go language quick start##

To test the Go installation process, we will create a workspace and build a simple program to print the classic "Hello World" message.

  1. By default, the GOPATH variable, specified as the location of the workspace, is set to $HOME/go. To create a workspace directory, enter:
mkdir ~/go
  1. In the workspace, create a new directory src/hello:
mkdir -p ~/go/src/hello

In that directory, create a new file with the name hello.go:

package main

import"fmt"

func main(){
 fmt.Printf("Hello, World\n")}

To learn more about the contents of the Go workspace, browse Go Document Page.

  1. Browse to the ~/go/src/hello directory, and run go build to build the program:
cd ~/go/src/hello
go build

The above command will build an executable file called hello.

  1. You can run this executable file by simply executing the following command:
. /hello

The output should look like this:

Hello, World

Three, summary##

Now that you have downloaded and installed Go on your Ubuntu system, you can start developing your Go project.

If you have any questions, please contact us in the following ways:

WeChat: sn0wdr1am86

WeChat group:
Add the above WeChat, note the WeChat group

QQ: 3217680847

QQ Group: 82695646

Recommended Posts

How to install Go on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Vagrant on Ubuntu 20.04
How to install Go on CentOS 8
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to install Nginx on Ubuntu 16.04
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04
How to install Postman on Ubuntu 18.04
How to install MySQL on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 20.04
How to install VLC on Ubuntu 18.04
How to install TeamViewer on Ubuntu 20.04
How to install Webmin on Ubuntu 20.04
How to install Docker Compose on Ubuntu 18.04
How to install Ubuntu on Raspberry Pi
How to install Bacula Server on Ubuntu 14.04
How to install MySQL on Ubuntu 18.04 (linux)
How to install Ubuntu 19.10 on Raspberry Pi 4
How to install Apache Kafka on Ubuntu 18.04
How to install Apache Maven on Ubuntu 20.04
How to install Apache Tomcat 8 on Ubuntu 16.04
How to install Python2 on Ubuntu20.04 ubuntu/focal64