• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install Go on Ubuntu 18.04

Written by Admin, Updated On December 23, 2019
go, ubuntu
How to Install Go on Ubuntu 18.04

Go is a modern open source programming language developed by Google. Popular applications such as, Grafana, Docker, etc. are written in Go language. In this tutorial shown how to install Go on Ubuntu 18.04 system.

Prerequisites#

Before you going to start, you should have non-root user account with sudo privileges.

Installing Go on Ubuntu#

Follow the steps given below to install Go on Ubuntu 18.04:

Downloading Go tarball#

Currently, latest stable version of Go is version 1.12.5 at the time of writing this article. You can check latest version of Go Download page.

You can download Go tarball using wget or curl:

wget https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz

Now, you should verify the tarball using below command:

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

Output should something like this:

Output
aea86e3c73495f205929cfebba0d63f1382c8ac59be081b6351681415f4063cf go1.12.5.linux-amd64.tar.gz

Make sure the output should exact match with the hash value provided at the Go download page.

Extracting the Go tarball#

Now extract the downloaded tarball using following command inside /usr/local directory.

sudo tar -C /usr/local -xzf go1.12.5.linux-amd64.tar.gz

Setting Go Path Variable#

You should set path environment variable in order to find Go executable binaries by system. For that we need to open /.profile using below command:

sudo nano ~/.profile

Now add the below lines to it:

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

Save and close the file. After that run below command to reload running profile:

source ~/.profile

Verifying the Go Installation#

You can verify the Go installation by Go version command:

go version

Output should look like this:

Output
go version go1.12.5 linux/amd64

Demo Program in Go#

Below is given a simple Hello World program in Go language which will print “Hello World” message. Follow the below steps to build simple program.

First of all we will create a workspace directory for Go. You can get more details about go workspace directory visit this page:

mkdir $HOME/demo

Next, create a src directory inside it using below command:

mkdir -p $HOME/demo/src/hello

In this directory create a file named hello.go and add below content to it:

sudo nano ~/demo/src/hello/hello.go
package main

import "fmt"

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

Now go back /demo/src/hello to build the file and issue go build command:

cd ~/demo/src/hello
go build

The above command will build an executable file with name hello.

You can run the program using executable using following command:

./hello
Output
Hello, World

Conclusion#

You have learned how to install Go on Ubuntu 18.04. If you have any queries feel free to comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install Yarn on CentOS 7
Next Article   How to Install Yarn on Debian 9

Related Posts

  • How to Install and Use PHP Composer on Ubuntu 22.04

    How to Install Composer on Ubuntu 22.04

    January 31, 2023
  • How to Install Nginx on Ubuntu 22.04

    How to Install Nginx on Ubuntu 22.04

    January 28, 2023
  • How to Install Puppet Agent on Ubuntu 22.04

    How to Install Puppet Agent on Ubuntu 22.04

    January 22, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Python 3.11 on Debian 11
    How to Install Python on Debian 11 January 25, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook