How to Install Go on CentOS 8

How to Install Go on CentOS 8

All

Linux Articles / All 60 Views comments

Go, also known as golang is a contemporary open-source programming language created by Google that lets you construct dependable and environment friendly purposes.

Many well-liked purposes, similar to Kubernetes, Docker, Prometheus, and Terraform, are written in Go.

This tutorial explains the right way to obtain and set up Go on CentOS eight.

Downloading and Putting in Go on CentOS eight

On the time of writing this text, the newest secure model of Go is model 1.13.four. Earlier than downloading the tarball, go to the official Go downloads page and examine if there's a new model obtainable.

Carry out the next steps under to obtain and set up Go on CentOS eight:

  1. Obtain the Go binary utilizing both the wget or curl utility:

    wget https://dl.google.com/go/go1.13.four.linux-amd64.tar.gz
  2. As soon as the archive is downloaded, confirm the tarball checksum by typing:

    sha256sum go1.13.four.linux-amd64.tar.gz

    Make certain the hash printed from the sha256sum command matches the one from the downloads web page.

    692d17071736f74be04a72a06dab9cac1cd759377bd85316e52b2227604c004c  go1.13.four.linux-amd64.tar.gz
  3. Extract the tarball to the /usr/native listing utilizing the tar command:

    sudo tar -C /usr/native -xf go1.13.four.linux-amd64.tar.gz

    The command above have to be run as root or a user with sudo privileges.

  4. Inform the system the place to seek out the Go executable binaries by adjusting the $PATH setting variable.

    You are able to do this by including the next line to the /and so on/profile file (for a system-wide set up) or to the $HOME/.bash_profile file (for a present consumer set up):

    ~/.bash_profile

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

    Save the file, and cargo the brand new PATH surroundings variable into the present shell session utilizing the source command:

    supply ~/.bash_profile

That is it. At this level, Go has been put in in your CentOS system.

Check the Set up

To check whether or not Go is put in appropriately, we'll arrange a workspace and construct a easy “Good day world” program.

  1. The situation of the workspace listing is specified with the GOPATH setting variable. By default, it's set to $HOME/go. To create the directory run the next command:

    mkdir ~/go
  2. Contained in the workspace create a brand new listing src/hey:

    mkdir -p ~/go/src/good day

    In that listing create a file named hiya.go:

    nano ~/go/src/hiya/whats up.go

    Paste the next code to the file:

    ~/go/src/good day/good day.go

    package deal essential
    
    import "fmt"
    
    func most important() 
        fmt.Printf("Hey, Worldn")
    
  3. Navigate to the ~/go/src/howdy listing and run go construct to construct the code:

    cd ~/go/src/hey
    go construct

    The command above will construct an executable named whats up.

  4. Run the executable by typing:

    ./good day

    For those who see the next output, then you've got efficiently put in Go.

    Good day, World

Conclusion

Now that you've downloaded and put in Go, you can begin writing your Go code.

For those who hit an issue or have suggestions, depart a remark under.

Comments