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
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. 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. Create a project directory and navigate into it:
mkdir go-hello && cd go-hello
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
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 Enter, then CTRL+X). Compile the program using go build, which creates an executable named after the last element of your module path (in this case, hello from example.com/hello):
go build
The command produces no output on success, which is expected behavior. For quick testing without creating a permanent executable, you can use go run hello.go to compile and run in a single step. 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. You can delete the test directory when finished:
cd ~ && rm -rf go-hello
Compile Go from Source
Compiling Go from source provides access to the latest release and allows custom build configurations. This method requires an existing Go installation as a bootstrap compiler; the DNF-installed version satisfies this requirement.
Install Build Dependencies
Ensure Git and GCC are installed before proceeding. 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
Create a build directory in your home folder. Using $HOME for build trees keeps source files organized and avoids permission issues during compilation:
mkdir -p ~/go-build && cd ~/go-build
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"
git clone --depth 1 --branch "go${GO_VERSION}" https://go.googlesource.com/go go-source
cd go-source/src
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 /home/username/go-build/go-source Installed commands in /home/username/go-build/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. This step requires sudo because /usr/local is a system directory:
sudo mv ~/go-build/go-source /usr/local/go
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.
Switch to the DNF-installed version:
sudo alternatives --set go /usr/lib/golang/bin/go
Switch back to the source-compiled version:
sudo alternatives --set go /usr/local/go/bin/go
To 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 while following proper permission practices.
Create the Update Script
The update script performs several safety checks before rebuilding:
- Privilege check: Refuses to run as root to prevent permission issues with build artifacts
- Tool check: Confirms required build tools (curl, git, gcc) are available
- Version detection: Fetches the latest version from GitHub and compares with your installed version
- Safe installation: Only uses sudo for the final install step
Create the script in your home directory:
nano ~/update-go.sh
Add the following script content:
#!/bin/bash
set -e
# Configuration
GOROOT_FINAL="/usr/local/go"
BUILD_DIR="$HOME/go-build"
LOG_FILE="$BUILD_DIR/update.log"
# Refuse to run as root
if [ "$(id -u)" -eq 0 ]; then
echo "Error: Do not run this script as root."
echo "Run as a regular user; the script uses sudo only for the install step."
exit 1
fi
# Check prerequisites
echo "Checking 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
# Create build directory
mkdir -p "$BUILD_DIR"
# 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
echo "Fetching 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"
echo "Check your internet connection or try again later."
exit 1
fi
echo "Current version: $CURRENT"
echo "Latest version: $LATEST"
if [ "$CURRENT" = "$LATEST" ]; then
echo "Already up to date."
exit 0
fi
echo ""
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
echo "Cloning Go source (this may take a moment)..."
git clone --depth 1 --branch "go${LATEST}" https://go.googlesource.com/go go-source
cd go-source/src
echo "Compiling Go (this takes 2-3 minutes)..."
GOROOT_BOOTSTRAP=/usr/lib/golang ./make.bash
# Remove old installation and install new (requires sudo)
echo "Installing to $GOROOT_FINAL (requires sudo)..."
sudo rm -rf "$GOROOT_FINAL"
sudo 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 ""
echo "Successfully updated to Go $NEW"
Save the file (CTRL+O, then Enter, then CTRL+X) and make it executable:
chmod +x ~/update-go.sh
Run the Update Script
Execute the script as your regular user (not with sudo). The script prompts for your password only when installing to the system directory:
~/update-go.sh
When your installation is already current, you will see:
Checking prerequisites... Fetching latest version from GitHub... Current version: 1.x.x Latest version: 1.x.x Already up to date.
When an update is available, the script automatically clones the new version, compiles it, and installs it. You will see progress messages throughout the process and a final confirmation showing the new version number.
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
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, remove it from alternatives first, then delete the installation directory:
sudo alternatives --remove go /usr/local/go/bin/go
The following command permanently deletes the source-compiled Go installation at
/usr/local/go. This directory contains the Go toolchain binaries, standard library, and documentation. User projects and downloaded modules in~/goare not affected.
sudo rm -rf /usr/local/go
The alternatives command automatically switches back to the DNF-installed version if it is still present. Verify with go version to confirm which version is now active.
If you created the update script, also remove the build directory and script:
rm -rf ~/go-build ~/update-go.sh
Clean Up User Data
Regardless of installation method, your personal workspace at ~/go and the build cache at ~/.cache/go-build remain untouched. These directories contain downloaded modules, compiled binaries, and cached build artifacts that can consume significant disk space over time.
The following command permanently deletes all Go modules, compiled binaries, and build cache. If you have projects that depend on downloaded modules, you will need to run
go mod downloadagain after recreating these directories.
rm -rf ~/go ~/.cache/go-build
Troubleshooting
Bootstrap Compiler Not Found
If you see an error like cannot find GOROOT_BOOTSTRAP when compiling from source, the DNF-installed Go is either missing or not in the expected location. Verify Go is installed:
ls -la /usr/lib/golang/bin/go
If the file does not exist, install Go via DNF first:
sudo dnf install golang
Alternatives Conflict After Removal
If go version fails after removing the source-compiled version, the alternatives system may still point to the deleted path. Reset alternatives to automatic mode:
sudo alternatives --auto go
If no alternatives remain, reinstall the DNF package:
sudo dnf reinstall golang
Permission Denied During Build
If the build fails with permission errors, you may have started the build with sudo or in a root-owned directory. Remove any root-owned build artifacts and rebuild in your home directory:
sudo rm -rf ~/go-build
mkdir -p ~/go-build && cd ~/go-build
Then follow the build steps again without using sudo until the final mv command.
Module Download Failures
If go mod download or go get fails with network errors, check your proxy settings and ensure the Go module proxy is reachable:
go env GOPROXY
https://proxy.golang.org,direct
If you are behind a corporate firewall that blocks the proxy, configure Go to fetch directly from source repositories:
go env -w GOPROXY=direct
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.