How to Install Go on Fedora 29/30

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Go compiles quickly to machine code yet has the convenience of garbage collection and the power of run-time reflection. It’s a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.

In this tutorial,we will show you how to Install Go on Fedora 30.

Prerequisites

Download and Install Go

Visit the page to Download the archive and extract it.You can use wget command to download the archive file.The latest stable version of the go is version 3.0.6. Check out the download page for the latest statble version.

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

After the download is complete, use the tar command to extract the downloaded archive to the specified directory (Ex:/opt/).

we will extract it into /opt/go, creating a Go tree in /opt/go. For example:

sudo tar -C /opt/go -xzf go1.12.5.linux-amd64.tar.gz

Now you have completed the go installation.

Set Environment variable

Add /opt/go/bin to the PATH environment variable. You can do this by adding this line to your /etc/profile(for a system-wide installation) or $HOME/.profile:

export PATH=$PATH:/opt/go/bin

If you have installed Go on custom location replace /opt/go/bin with ‘/path/go/bin’ directory.

You need create your workspace directory,for example $HOME/gowork .You will need to set the DGOPATH environment variable for your project workspace.

Add this line to your /etc/profile(for a system-wide installation) or$HOME/.profile`:

export GOPATH=$HOME/gowork

To apply the changes immediately, just run the shell commands using follow command:

source $HOME/.profile

Verify Go Installation

To verify the current version of go,Type follow command:

go version

The output will look something like this:

go version go1.12.5 linux/amd64

Check the Go environment variables, type follow command:

go env

The output will look something like this:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/linuxhowto/gowork"
GORACE=""
GOROOT="/opt/go"
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

Create Project

Now your go workspace is the directory $HOME/gowork,make the directory src/hello inside your workspace,and in that directory create a file named hello.go that looks like below:

package main

import "fmt"

func main() {
	fmt.Printf("Hello,LinuxHowto.info!\n")
}

Then build it with the go tool:

cd $HOME/gowork/src/hello
go build

After the command is executed,you will find an executable file named hello under the directory $HOME/gowork/src/hello.

Execute it to see the greeting:

./hello
Hello,LinuxHowto.info!

If you see the “Hello, LinuxHowto.info!” message then your Go installation is working.

You can run go install to install the binary into your workspace’s bin directory or go clean -i to remove it.

Conclusion

That’s all. You have learned how to install go on Fedora 30,and create your first go project.

If you have any questions or thoughts to share, feel free to leave a comment..

Leave a Reply