How to install the Golang on Ubuntu Cloud Servers

2021-03-30 By Mark 56 Views linux golang development
0 reviews

Golang (Go) is a powerful system-level language used for programming across large network servers and large distribution systems. It was previously written in C but is now written in Go itself. This tested and proves that the applications written in Go are very performance and scalable.


This guide will describe the installation of the Latest Version of Golang on Ubuntu system.


  1. Take SSH access to the Ubuntu Cloud server as root or a sudo user.

  2. Run the below command to update the server first before proceed the installation.

    # apt-get update
    

    golang1

  3. Change to a temporary directory and select the latest package for your architecture from the following https://golang.org/dl/ and download.

    # cd /tmp
    
    # wget https://golang.org/dl/go1.16.2.linux-amd64.tar.gz
    

    golang2

  4. Now extract the Golang executable to the /usr/local directory.

    # tar -C /usr/local -xzf gol.16.2.linux-amd64.tar.gz
    

    golang3

  5. To use Golang, set the below environment variables in your .profile.

    # echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.profile
    
    # echo "export GOPATH=~/.go" >> ~/.profile
    

    golang4

  6. Now Reload your profile with the below command to begin using Golang.

    # source ~/.profile
    

    golang5

  7. Verify the version of Golang with the below command.

    # go version
    

    golang6

  8. To test the environment, create a go file.

    # vi layerstack.go
    


    Paste the below simple programe in that file:

    package main
    
    import "fmt"
    
    func main() {  
    fmt.Println("Welcome to Layerstack")  
    }
    


    Once it created, then run the below command to run the programe.

    # go layerstack.go
    

    golang7

    NOTE: You can change any file name as you need.

What do you think about this article?

Rate this article