Which of /usr/bin/perl or /usr/local/bin/perl should be used?
It depends: on some systems, e.g. BSD packaging, /usr/local/bin
may be the directory where packages install executables. In that case, it would be newer (and perhaps better), but /usr/bin/perl
would be more stable.
You can use perl -V
to see which has a newer version number. Sometimes the contents of /usr/local/bin
(on multi-user systems) isn't really newer.
The usual compromise is to let the user decide, by using env
in the shebang/hashbang line (but again, the path to env
can vary by system).
The shebang line refers to the first line of a script, which may look like one of the following:
#!/usr/bin/perl
#!/usr/bin/perl -w
#!/usr/bin/env perl
The first two specify the directory from which to run Perl. As a bonus, this form allows passing an option, e.g. -w
(used to turn on warnings). The last line uses the env
program to pick the first occurrence of perl
by searching the directories listed in the user's PATH
environment variable.
It is also possible to run a script like this:
perl myscript
which (like env
) tells the shell to pick the first occurrence of perl
from the directories listed in PATH
.
An explicit
./perl myscript
of course overrides the PATH
. But scripts with shebang lines are the way most people use Perl scripts (Perl one-liners are a different matter).
Further reading:
- /usr/bin/env perl - query, referring to shebang line
- /usr/bin vs /usr/local/bin on Linux
-
pkg(7), FreeBSD package system with
/usr/local/bin
Related videos on Youtube
CJ7
Updated on September 18, 2022Comments
-
CJ7 over 1 year
If I have both
/usr/bin/perl
and/usr/local/bin/perl
available on a system, which one should I use? -
CJ7 about 8 yearsIf I run
perl
from my home directory, whichperl
will be executed? -
muru about 8 years@CJ7 Run
type perl
orcommand -v perl
to find out -
muru about 8 years@CJ7 as Thomas has already said, the
PATH
environment variable. -
Mayur A Muley about 8 yearsThis is the first time I've heard of the shebang referred to as a "hash-tag line"...
-
schaiba about 8 yearsAs other have said,
echo $PATH
should show you which location is used first. -
Angel Todorov about 8 yearsTo examine the PATH, I like to use
tr : '\n' <<<":$PATH"
-
Marius about 8 yearshashtag is a neologism when used in the sense @Bob is familiar. It's derived from one sense of the use of hashmark (with which some commenters also are apparently unfamiliar). For examining the
PATH
, I use a script except when explaining howPATH
works. ymmv.