You need Go, and the terminal says no
You cloned a repository. You ran the build command. The shell replied with go: command not found. You are on Fedora. You need the Go toolchain. The solution is straightforward, but the method depends on whether you need the latest stable release, a specific version for a legacy project, or the absolute newest version from the Go team.
Ignore any guide telling you to enable Software Collections (SCL) or centos-sclo-rpms. That repository exists for RHEL and CentOS derivatives. Fedora uses the main repositories and module streams. Enabling SCL on Fedora adds unnecessary complexity and can break dependency resolution. Stick to dnf.
How Fedora packages Go
Fedora ships Go in the main repositories. The package is named golang. It includes the compiler, the linker, the standard library, and the go command. The package manager handles all dependencies. You get a toolchain that is tested against the Fedora release and updated alongside the system.
Fedora also supports module streams. A module stream lets you switch between major Go versions without downloading tarballs manually. The module system locks the system to a specific stream. You can reset the stream and switch to another version if your project requires it.
The golang package installs the toolchain to /usr/lib/golang. The binary is symlinked to /usr/bin/go. This path is already in your PATH. You do not need to configure environment variables to run the compiler. Go's workspace variables like GOPATH default to ~/go. You control the workspace. Fedora controls the toolchain.
Run dnf upgrade --refresh before installing new development tools. This ensures the metadata is current and you pull the latest package versions.
Install the standard version
The default installation gives you the Go version Fedora considers stable for your release. This is the right choice for most users. It integrates with the system update cycle. When Fedora updates Go, your toolchain updates automatically.
Here's how to install the standard Go toolchain and verify the metadata is fresh.
sudo dnf upgrade --refresh # WHY: Refreshes repository metadata to ensure you get the latest package versions.
sudo dnf install golang # WHY: Installs the Go toolchain from the main repository.
The package manager resolves dependencies and places the binary on your system. The installation is atomic. If the transaction fails, your system remains unchanged.
Open a new terminal session after the install. The PATH variable was set before the binary appeared. The current shell might not see the new command. If you must stay in the current session, run hash -r to clear the command cache.
Verify the installation
Run the version command to confirm the toolchain is accessible. This command checks that the binary is on your PATH and reports the version string.
go version # WHY: Prints the installed version. If this fails, your PATH is misconfigured or the install did not complete.
You should see output like go version go1.21.5 linux/amd64. The version number reflects the release Fedora packaged. It might be slightly older than the absolute latest upstream release. Fedora prioritizes stability over bleeding-edge versions in the main repo.
Check the environment variables to understand where Go will store your code and binaries. This output shows the defaults.
go env GOPATH GOBIN # WHY: Displays the workspace root and binary directory. Go uses these paths for 'go install'.
The default GOPATH is ~/go. Your source code lives in ~/go/src. Binaries built with go install land in ~/go/bin. Add ~/go/bin to your PATH if you plan to use go install for tools. The Fedora package does not set this for you. This is standard Go practice, not a Fedora quirk.
Use go env -w to set variables persistently. This writes to ~/.config/go/env.json. Editing ~/.bashrc for Go variables is legacy. The built-in config is cleaner and works across shells.
Manage versions with modules
Some projects require a specific Go version. The module system lets you switch streams. You cannot install two versions side-by-side via modules. You must reset the current stream before switching.
Here's how to list available streams and switch to a specific version.
sudo dnf module list golang # WHY: Shows available streams and profiles. Look for the 'stream' column.
sudo dnf module reset golang # WHY: Clears the active stream selection. Required before switching versions.
sudo dnf module install golang:1.21 # WHY: Installs the 1.21 stream if available. Replace 1.21 with your target stream.
The reset command is essential. Fedora modules lock to a stream. Attempting to install a different version without resetting results in a conflict error. The package manager refuses to proceed. Resetting clears the lock and allows the new stream to take over.
If the stream you need is not listed, Fedora does not package it as a module. You must use the official tarball or wait for Fedora to add the stream. Check the Fedora release notes for module availability.
Common pitfalls and error messages
Errors usually stem from path conflicts, stale caches, or version mismatches. Diagnose the symptom before guessing.
The go version command prints an older version than you installed. You likely have a user-local Go installation in ~/go/bin or /usr/local/go/bin that shadows the system binary. Check your PATH. The first go found wins. Remove the old binary or reorder the PATH.
which go # WHY: Shows the full path of the go binary being executed.
echo $PATH # WHY: Displays the search order. Verify /usr/bin appears before ~/go/bin.
The build fails with go: cannot find main module. You are running go build in a directory without a go.mod file. Initialize the module first.
go mod init example.com/myproject # WHY: Creates a go.mod file. Required for module-aware builds.
You see SELinux is preventing go from accessing... in the logs. You compiled a binary that listens on a port or accesses restricted files. SELinux applies to Go binaries just like any other executable. Do not disable SELinux. Check the denial message.
journalctl -t setroubleshoot | tail -20 # WHY: Shows SELinux denial summaries. Read the one-liner for the fix.
The setroubleshoot service generates a human-readable summary. Follow the suggested command to restore context or install a policy module. Manual file edits drift. Snapshots stay.
Choose the right installation method
Pick the method that matches your workflow. Each approach has trade-offs in maintenance, version control, and integration.
Use dnf install golang when you want the default stable version managed by Fedora. The system updates handle the toolchain. You get security patches and bug fixes automatically. This is the best choice for general development and CI runners.
Use dnf module install golang:stream when you need a specific version that Fedora packages as a module stream. This gives you version control without manual downloads. You still benefit from package manager updates within the stream. Use this for projects locked to a major Go version.
Use the official tarball from golang.org when you require a version not available in Fedora or you need the release day-zero. Download the tarball, extract it to /usr/local, and manage the binary manually. You lose automatic updates. You must track upstream releases and apply patches yourself. Use this only when Fedora's version is insufficient.
Run go version before every major build. Verify the toolchain matches the project requirements. A mismatched compiler can produce subtle runtime errors.