FreeBSD: Why is the older version of a binary used by default?

Joined
Oct 22, 2019
Messages
3,641
This applies to TrueNAS Core in general, and the FreeBSD operating system and jails more specifically.

Perhaps this is not unique to FreeBSD? (Though I've never noticed it on a Linux distro.)

Perhaps this only applies to certain binaries?


After installing the package zstd in a jail, here are the results of the following commands.


FreeBSD version is 13.1-REALEASE-p7:
Code:
freebsd-version
13.1-REALEASE-p7


Running straight zstd uses an older version:
Code:
zstd --version
*** zstd command line interface 64-bits v1.4.8, by Yann Collet ***


The same is true, of course, for /usr/bin/zstd:
Code:
/usr/bin/zstd --version
*** zstd command line interface 64-bits v1.4.8, by Yann Collet ***


However, invoking /usr/*local*/bin/zstd uses the newer version, installed via "pkg":
Code:
/usr/local/bin/zstd --version
*** Zstandard CLI (64-bit) v1.5.4, by Yann Collet ***


Naturally, this is due the the default PATH, /usr/bin comes before /usr/local/bin:
Code:
echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin



This leads me to believe that it will also occur with other binaries installed via "pkg", as they will be placed under /usr/local/bin, meanwhile the existing binaries under /usr/bin will take priority. (The "zstd" program is already installed and available with a newly created jail even before installing anything with "pkg".)


Question 1:
Why is this the default behavior? As a user, you would expect that the binaries/libraries installed via "pkg" would take priority, since they are more recent and are constantly updated. (I want to use zstd version 1.5.4, not 1.4.8. It's newer and has performance improvements, for example. It was by accident I discovered that an older version was being used when running the command "zstd".)

Question 2:
Does this also imply that "tar" will invoke the binary/libraries of the older version of zstd as well? Such as when running:
Code:
tar -c -a -f archive.tar.zst sourcefile
 
Last edited:
Joined
Oct 22, 2019
Messages
3,641
I created this thread just minutes ago. I hate it when this happens. o_O

hate-when-this-happens.png


Using Google doesn't fare much better either: a bunch of results about how to downgrade to an older version of a package, or an assortment of discussions about FreeBSD versions in general...
 

c77dk

Patron
Joined
Nov 27, 2019
Messages
468
could this be related to the order in PATH environment? Haven't tested, but just my first thought
 
Joined
Oct 22, 2019
Messages
3,641
could this be related to the order in PATH environment?
It is, which is what I showed in my first post.

The issue is more of a "Why?" Because installing binaries via "pkg", I'd expect them to have priority, either when invoking the name of the command (such as "zstd") or when used by other applications (such as "tar".)

"zstd" is just the obvious example that I bumped into by mistake. Regardless of how many updates it receives via "pkg" (currently on version 1.5.4 now, which has performance enhancements), the older version 1.4.8 takes priority because of the order in PATH. :confused:
 
Last edited:

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
The default search path is defined in /etc/login.conf and is per default: path=/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin ~/bin

The reasoning is that system provided known stable and consistent binaries should take precedence. You are free to create shell aliases or change the path for your interactive account as you see fit.
 
Joined
Oct 22, 2019
Messages
3,641
Maybe a stability or branch thing.
The reasoning is that system provided known stable and consistent binaries should take precedence.

That makes sense. Being a "Linux user" myself, I'm still getting used to certain philosophies of FreeBSD. :wink: I couldn't find this explicit reasoning, as much as I searched for it.


It still leaves me with the other question (#2), which is somewhat related, and I think I might know the answer now:

Does the "tar" command use the binary/library of version 1.4.8 (as it's the "known stable" one), regardless of whether or not the binary/library is installed via "pkg", and regardless of changing the order in PATH?
Code:
tar -c -a -f archive.tar.zst sourcefile
 

c77dk

Patron
Joined
Nov 27, 2019
Messages
468
It is, which is what I showed in my first post.

The issue is more of a "Why?" Because installing binaries via "pkg", I'd expect them to have priority, whether when invoking the name of the command (such as "zstd") or when used by other applications (such as "tar".)

"zstd" is just the obvious example that I bumped into by mistake. Regardless of how many updates it receives via "pkg" (currently on version 1.5.4 now, which has performance enhancements), the older version 1.4.8 takes priority because of the order in PATH. :confused:
d'oh! I need more coffee, or maybe some sleep would be a better idea .... missed that part completely :-(
 
Joined
Oct 22, 2019
Messages
3,641
d'oh! I need more coffee, or maybe some sleep would be a better idea .... missed that part completely :-(
It's all good! I'm still learning and figuring this stuff out as I go along. :tongue:
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Does the "tar" command use the binary/library of version 1.4.8 (as it's the "known stable" one), regardless of whether or not the binary/library is installed via "pkg", and regardless of changing the order in PATH?
The tar command is - if you have not changed your default path - /usr/bin/tar and that is linked with the base system libraries and will never pull in anything from /usr/local. Who guarantees that the supposedly newer libraries in /usr/local/lib are even remotely ABI compatible?

Base system is base system and additional software is additional software. You need to install some tar variant from packages that links with your newer zstd library from packages and then call that one explicitly or change your search path.

In short: the FreeBSD base system is 100% self contained an does not need neither give a damn about what you install somewhere else. Installed software might rely on certain parts of base but not the other way round.
 
Top