[Bug 296467] pkg upgrade installs unrelated, unnecessary other packages

From: <bugzilla-noreply_at_freebsd.org>
Date: Sat, 04 Jul 2026 17:43:30 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296467

--- Comment #7 from Mark Millard <marklmi26-fbsd@yahoo.com> ---
(In reply to wbe from comment #6)

> *why* they would need gcc-anything as a dependency is still a mystery to me

Linux tends to split the run-time libraries programs use from the
toolchain. FreeBSD ports tend not to do that. I'll use a simple
benchmark program to illustrate: benchmarks/stream . Note the path:
/usr/local/lib/gcc16/libgomp.so.1 below.

# ldd /usr/local/bin/stream_bench_omp
/usr/local/bin/stream_bench_omp:
        libgomp.so.1 => /usr/local/lib/gcc16/libgomp.so.1 (0x420f86bd0000)
        libthr.so.3 => /lib/libthr.so.3 (0x420f82a80000)
        libc.so.7 => /lib/libc.so.7 (0x420f84c00000)
        libdl.so.1 => /usr/lib/libdl.so.1 (0x420f83620000)
        libsys.so.7 => /lib/libsys.so.7 (0x420f91d70000)

Based on how the FreeBSD ports are structured, in order to have that
file present, lang/gcc16 must be installed even though the compiler
and linker and the like were only used at build time.

> When you speak of orphaned files . . .

Being more careful in my below more detailed descriptions
this time:

Orphaned files of one type are ones for which no enabled repository
for the specific command has the package that was used to do the
install/upgrade but pkg still has database records about the
install/upgrade. pkg has a means of reporting these packages that
have no "parent" (given the same set of enabled repositories for
that command as well).

Orphaned files of another type are ones where pkg has no database
record in the install/upgrade any more: those files are as if they
had been hand copied into place instead of having used pkg to get
them in place. For these pkg has no information with which to
delete the files just before installing/upgrading to the new set
of files. Such activity tends to create *.pkgsave files and/or
*.pkgnew files.

The following command will list what port packages are from
the FreeBSD repository:

# pkg query %R:%n-%v | grep ^FreeBSD:

I do not have that repository name, so an example using a
name I do have:

# pkg query %R:%n-%v | grep ^main-aarch64-default: | head
main-aarch64-default:acpica-tools-20260408
main-aarch64-default:arcanist-lib-php84-20230530
main-aarch64-default:arm-gnueabi-binutils-2.44,1
main-aarch64-default:bash-5.3.15
main-aarch64-default:binutils-2.44,1
main-aarch64-default:bonnie-2.0.6_2
main-aarch64-default:bonnie++-1.98_1
main-aarch64-default:boost-libs-1.89.0_2
main-aarch64-default:brotli-1.2.0,1
main-aarch64-default:bsdadminscripts2-0.5.1

The following is an example of then removing the repository
prefix (illustrated with mine and shortening the output with
head):

# pkg query %R:%n-%v \
| grep ^main-aarch64-default: \
| sed -e 's@^[^:]*:\(.*\)$@\1@'
| head
acpica-tools-20260408
arcanist-lib-php84-20230530
arm-gnueabi-binutils-2.44,1
bash-5.3.15
binutils-2.44,1
bonnie-2.0.6_2
bonnie++-1.98_1
boost-libs-1.89.0_2
brotli-1.2.0,1
bsdadminscripts2-0.5.1

With that information one can then force an upgrade of those
using a specific repository to do the upgrade (back to your
context):

# pkg upgrade -rFreeBSD-ports -f \
$(pkg query %R:%n-%v | grep ^FreeBSD: | sed -e 's@^[^:]*:\(.*\)$@\1@')

After that the command:

# pkg query %R:%n-%v | grep ^FreeBSD:

should generate an empty list.

At that point deletion (or disabling) of the FreeBSD
repository reference in /usr/local/etc/pkg/repos/ is
appropriate.

Then:

# pkg clean

should get back relevant space under: /var/cache/pkg/

Then you should be able to:

# rm /var/db/pkg/repos/FreeBSD /var/db/pkg/*FreeBSD.*

-- 
You are receiving this mail because:
You are on the CC list for the bug.
You are the assignee for the bug.