I'm working on an older Debian 6 machine. It had an old version of Perl and it was causing some self tests to fail with "Test::More version 0.96 required". I downloaded the latest Perl 5.22.1, built it from sources and placed it at /opt/perl/.

I have a script that use Perl, and its preamble is:

#!/usr/bin/env perl

However, when I execute the script, it is using the old Perl instead of the new Perl. This is kind of expected because /usr/bin/env does not know about Perl (or I don't believe it does).

How do I tell env that Perl is the one in /opt/perl/, and not /usr/bin/? If possible, I'd like it to be a machine configuration (i.e., applies to everyone), and not a user configuration (i.e., applies to just me).

Here is the manpage for env(1). There's not much to it, and I don't believe it discusses registering a new version of a program for an interpreter. There are no man pages for env(7) (miscellaneous) or env(8) (administration).

ENV(1)                           User Commands                          ENV(1)

       env - run a program in a modified environment

       env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]

       Set each NAME to VALUE in the environment and run COMMAND.

       -i, --ignore-environment
              start with an empty environment

       -0, --null
              end each output line with 0 byte rather than newline

       -u, --unset=NAME
              remove variable from the environment

       --help display this help and exit

              output version information and exit

       A mere - implies -i.  If no COMMAND, print the resulting environment.

       Written by Richard Mlynarik and David MacKenzie.

  • As a temporary measure you can try renaming perl binary in /bin and replace it with simlink to the one in /opt to see if it works. – Oleg Bolden Mar 30 '16 at 17:44

Like shell, env uses $PATH to find the executable file for a simple command name. (Unlike shell it doesn't try aliases, functions, and builtins first.) I don't have Debian at hand, but on my Ubuntu 14.04 (which shouldn't be much different) standard/packaged perl is in /usr/bin, and a test user with no customization gets a $PATH setting of


plus the default .profile checks if $HOME/bin exists and if so adds it at the front.

/usr/local/* is intended precisely for "specific to my system" overrides, and ~username/bin for "this user only" overrides, so a symlink in any of them should work. Alternatively you could put /opt/perl (or maybe /opt/perl/bin if it's structured that way) in your $PATH prior to /usr/bin.

  • "/usr/local/\* is intended precisely for "specific to my system" overrides..." - the problem here is Perl pollutes the directory it touches. Its one thing if it installs one or two programs, a few libs, etc. But Perl sprays stuff all over the directories it touches. Its one of the reasons I did not want to use /usr/local. – jww Mar 30 '16 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.