Go (commonly called Golang) is a compiled programming language developed by Google that excels at building REST APIs, command-line tools, network services, and cloud-native applications. Its built-in concurrency support, fast compilation, and straightforward cross-compilation to other platforms make it particularly well-suited for microservices, container orchestration tools like Kubernetes, and high-performance web backends. By the end of this guide, you will have Go installed on Fedora, understand the default environment paths, and verify your setup with a working test application.
Choose Your Go Installation Method
You can install Go on Fedora using either the DNF package manager or by compiling from source. The table below outlines the key differences:
| Method | Channel | Version | Updates | Best For |
|---|---|---|---|---|
| DNF Package Manager | Fedora Repos | Distribution default | Automatic via dnf upgrade | Most users who want simple, stable setup |
| Source Compilation | GitHub | Latest stable | Script-assisted recompilation | Developers needing specific versions or patches |
For most users, the DNF method is recommended because Fedora typically ships recent Go versions and provides automatic security updates. Only compile from source if you specifically need a version not yet available in the repositories or require custom build flags.
Update Fedora System
First, update your Fedora system to ensure all packages and dependencies are current. This step helps avoid potential conflicts during the Go installation:
sudo dnf upgrade --refresh
Install Golang with DNF
Once the system update completes, install Go from Fedora’s default repositories:
sudo dnf install golang
After the installation finishes, verify that Go is accessible by checking its version:
go version
go version go1.x.x linux/amd64
This output confirms Go is installed and ready to use. Additionally, Fedora installs Go to /usr/lib/golang (GOROOT) by default, while your workspace defaults to ~/go (GOPATH) for downloaded modules and compiled binaries.
Create and Run a Test Application
With Go installed, create a simple “Hello World” program to verify everything works correctly. First, create a project directory and navigate into it:
mkdir go-hello && cd go-hello
Next, initialize a new Go module. The go mod init command creates the required go.mod file that tracks your project’s dependencies:
go mod init example.com/hello
go: creating new go.mod: module example.com/hello
Now create the main Go source file:
nano hello.go
Add the following code to create the “Hello World” program:
package main
import "fmt"
func main() {
fmt.Println("Hello, World from LinuxCapable.com")
}
Save the file (CTRL+O), then exit (CTRL+X). Now compile the program using go build, which creates an executable named after your module (in this case, hello):
go build
The command produces no output on success, which is expected behavior. For quick testing without creating a permanent executable, you can alternatively use go run hello.go to compile and run in a single step. Now run the compiled program:
./hello
Hello, World from LinuxCapable.com
This output confirms that your Go installation is working correctly and you can compile and run Go programs.
Compile Go from Source
Compiling Go from source provides access to the latest release and allows custom build configurations. However, this method requires an existing Go installation as a bootstrap compiler—the DNF-installed version satisfies this requirement.
Install Build Dependencies
First, ensure Git and GCC are installed. Git clones the source repository, and GCC enables cgo support for programs that interface with C libraries:
sudo dnf install git gcc
Download and Build Go
The following commands automatically detect the latest stable Go version, clone the source, and compile the toolchain. The build process takes approximately 2-3 minutes depending on your system:
GO_VERSION=$(curl -s https://api.github.com/repos/golang/go/git/refs/tags | grep -oP '"ref": "refs/tags/go\K[0-9]+\.[0-9]+\.[0-9]+"' | tr -d '"' | sort -V | tail -1)
echo "Building Go version: $GO_VERSION"
cd /opt
sudo git clone --depth 1 --branch "go${GO_VERSION}" https://go.googlesource.com/go go-source
cd /opt/go-source/src
sudo GOROOT_BOOTSTRAP=/usr/lib/golang ./make.bash
When the build completes successfully, you will see output similar to:
Building Go toolchain3 using go_bootstrap and Go toolchain2. Building packages and commands for linux/amd64. --- Installed Go for linux/amd64 in /opt/go-source Installed commands in /opt/go-source/bin
Install to System Location
After the build completes, move the compiled Go installation to the standard system location at /usr/local/go:
sudo mv /opt/go-source /usr/local/go
Next, register the source-compiled version with Fedora’s alternatives system. This integrates it with the existing /usr/bin/go symlink that the DNF package created:
sudo alternatives --install /usr/bin/go go /usr/local/go/bin/go 100 \
--follower /usr/bin/gofmt gofmt /usr/local/go/bin/gofmt
Because the priority value of 100 is higher than the DNF package’s default priority of 90, the source-compiled version becomes the default automatically. To confirm, verify which version is now active:
go version
go version go1.x.x linux/amd64
Switch Between Go Versions
If you have both the DNF-installed and source-compiled versions, Fedora’s alternatives system lets you switch between them without modifying your PATH. Before switching, check which versions are available:
alternatives --display go
go - status is auto. link currently points to /usr/local/go/bin/go /usr/lib/golang/bin/go - priority 90 /usr/local/go/bin/go - priority 100 Current `best' version is /usr/local/go/bin/go.
For switching to the DNF-installed version, run:
sudo alternatives --set go /usr/lib/golang/bin/go
Alternatively, switch back to the source-compiled version with:
sudo alternatives --set go /usr/local/go/bin/go
Finally, restore automatic selection based on priority (highest priority wins):
sudo alternatives --auto go
The alternatives system manages the
/usr/bin/gosymlink system-wide. You can verify which version is active at any time withgo versionorreadlink -f /usr/bin/goto see the full path.
Update Source-Compiled Go
If you compiled Go from source, you can create an update script that automatically detects the latest version and rebuilds when updates are available. This script checks the GitHub API, compares versions, and handles the complete rebuild process.
First, create a directory for the update script and build artifacts:
sudo mkdir -p /opt/go-build
Next, create the update script:
sudo nano /opt/go-build/update-go.sh
Add the following script content:
#!/bin/bash
set -e
# Configuration
GOROOT_FINAL="/usr/local/go"
BUILD_DIR="/opt/go-build"
LOG_FILE="$BUILD_DIR/update.log"
# Check prerequisites
for cmd in gcc git curl; do
if ! command -v $cmd &> /dev/null; then
echo "Error: $cmd is required but not installed."
echo "Run: sudo dnf install gcc git curl"
exit 1
fi
done
# Get current installed version
CURRENT=$($GOROOT_FINAL/bin/go version 2>/dev/null | grep -oP 'go\K[0-9]+\.[0-9]+\.[0-9]+' || echo "none")
# Fetch latest version from GitHub
LATEST=$(curl -s https://api.github.com/repos/golang/go/git/refs/tags | grep -oP '"ref": "refs/tags/go\K[0-9]+\.[0-9]+\.[0-9]+"' | tr -d '"' | sort -V | tail -1)
if [ -z "$LATEST" ]; then
echo "Error: Could not fetch latest version from GitHub API"
exit 1
fi
echo "Current version: $CURRENT"
echo "Latest version: $LATEST"
if [ "$CURRENT" = "$LATEST" ]; then
echo "Already up to date."
exit 0
fi
echo "Updating from $CURRENT to $LATEST..."
echo "$(date): Starting update to $LATEST" >> "$LOG_FILE"
cd "$BUILD_DIR"
# Clean previous builds
rm -rf go-source/
# Clone and build
git clone --depth 1 --branch "go${LATEST}" https://go.googlesource.com/go go-source
cd go-source/src
GOROOT_BOOTSTRAP=/usr/lib/golang ./make.bash
# Remove old installation and install new
rm -rf "$GOROOT_FINAL"
mv "$BUILD_DIR/go-source" "$GOROOT_FINAL"
# Verify
NEW=$($GOROOT_FINAL/bin/go version | grep -oP 'go\K[0-9]+\.[0-9]+\.[0-9]+')
echo "$(date): Updated to $NEW" >> "$LOG_FILE"
echo "Successfully updated to Go $NEW"
Save the file and make it executable:
sudo chmod +x /opt/go-build/update-go.sh
To check for updates and rebuild if needed, run the script with sudo:
sudo /opt/go-build/update-go.sh
Current version: 1.25.5 Latest version: 1.25.5 Already up to date.
Avoid automating this script with cron. Compilation can fail due to network issues, disk space, or dependency changes between major Go releases. Always run the script manually so you can monitor the output and address any problems before they affect your development environment.
Remove Golang
The removal process depends on which installation method you used.
Remove DNF-Installed Go
If you installed Go using DNF, remove it with:
sudo dnf remove golang
As a result, DNF automatically removes the golang-bin and golang-src packages along with any unused dependencies.
Remove Source-Compiled Go
If you compiled Go from source and registered it with the alternatives system, first remove it from alternatives, then delete the installation directory:
sudo alternatives --remove go /usr/local/go/bin/go
sudo rm -rf /usr/local/go
Consequently, the alternatives command automatically switches back to the DNF-installed version if it’s still present. You can verify with go version to confirm which version is now active.
If you created the update script, also remove the build directory:
sudo rm -rf /opt/go-build
Clean Up User Data
Regardless of installation method, your personal workspace at ~/go and the build cache at ~/.cache/go-build remain untouched. In particular, these directories contain downloaded modules, compiled binaries, and cached build artifacts.
To completely remove Go-related user data, delete the workspace and cache directories:
rm -rf ~/go ~/.cache/go-build. This can free significant disk space if you worked on multiple Go projects.
Conclusion
You now have Go installed on Fedora with a verified working environment. From here, you can start building web services, CLI applications, or contribute to Go-based projects. For version control, consider setting up Git on Fedora to manage your Go projects. If you plan to containerize your applications, our Docker installation guide covers the setup process. For a full-featured development environment, Visual Studio Code offers excellent Go support through the official Go extension. If you are exploring compiled languages, you might also be interested in Rust on Fedora, which shares Go’s focus on performance and safety.
For tutorials, language references, and module documentation, visit the official Go documentation.