Skip to content

Instantly share code, notes, and snippets.

@RikudouSage
Created December 11, 2025 08:35
Show Gist options
  • Select an option

  • Save RikudouSage/bec15fa61a74b231b54818623661205a to your computer and use it in GitHub Desktop.

Select an option

Save RikudouSage/bec15fa61a74b231b54818623661205a to your computer and use it in GitHub Desktop.
%global goversion @GOVERSION@
%global goos @GOOS@
%global goarch @GOARCH@
%global __requires_exclude_from ^/opt/go/%{goversion}/src/.*\.rc$
AutoReq: 0
AutoProv: 0
Name: go
Version: %{goversion}
Release: 1%{?dist}
Summary: Go toolchain %{goversion} for %{goos}-%{goarch} under /opt
Provides: go
License: BSD and MIT
URL: https://go.dev
Source0: https://go.dev/dl/go%{goversion}.%{goos}-%{goarch}.tar.gz
BuildArch: %{_arch}
%description
Go programming language toolchain version %{goversion} for %{goos}-%{goarch},
installed under /opt/go/%{goversion}. The package also manages /usr/bin/go
as a symlink in its post-install script.
%prep
# no-op; we install prebuilt tarball in %%install
%build
# no-op
%install
rm -rf %{buildroot}
# Install the toolchain under /opt/go/<version>
mkdir -p %{buildroot}/opt/go/%{goversion}
tar -C %{buildroot}/opt/go/%{goversion} \
--strip-components=1 \
-xzf %{SOURCE0}
# NOTE: we do NOT create /usr/bin/go here; that’s handled in %%post
# and /usr/bin/go is NOT listed in %%files, to avoid package conflicts.
%post
# $1 is the RPM transaction state; 1 = install, 2 = upgrade
# Always point /usr/bin/go at this version on install/upgrade.
ln -sfn /opt/go/%{goversion}/bin/go /usr/bin/go || true
%postun
# $1 = 0 on final erase
if [ "$1" -eq 0 ]; then
# Only remove /usr/bin/go if it currently points to THIS version.
if [ -L /usr/bin/go ] && [ "$(readlink /usr/bin/go)" = "/opt/go/%{goversion}/bin/go" ]; then
rm -f /usr/bin/go
fi
fi
%files
%license /opt/go/%{goversion}/LICENSE
%doc /opt/go/%{goversion}/README.md
%dir /opt/go
%dir /opt/go/%{goversion}
/opt/go/%{goversion}
%changelog
* Wed Dec 10 2025 Dominik Chrástecký <[email protected]> - %{goversion}-1
- Initial Go toolchain packaging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment