Andrey Yumashev
Andrey Yumashev

Reputation: 59

Replace default perl on Ubuntu 16.04

I got a huge project written on Perl, which contains many of scripts which starts with typical #!/usr/bin/perl

For this project I need a custom-built Perl to be compiled from source.

I tried just to replace /usr/bin/perl with my compiled one but OS becomes broken (for ex. module version mismatch etc).

So is there any correct way to replace system perl with my own-built one or the easiest way would be to edit all tons of scripts and replace /usr/bin/perl with /usr/local/bin/perl or something like this?

Upvotes: 2

Views: 1489

Answers (2)

Andrey Yumashev
Andrey Yumashev

Reputation: 59

According to comments, there is no solution to replace system Perl without of destroying something but the're 3 solutions to solve the descibed problem. For all of them i need to modify all the scripts.

  1. Using #!/usr/bin/env perl (need to be very careful and place custom perl bin path before all at $PATH of user which runs the script. The nice solution would be to set PATH exactly at crontab.
  2. Using straight new perl path at shebang like as #!/usr/local/bin/perl5.26.1
  3. Totally remove shebang from scripts and use plain calls at cron and manual runs - like as /usr/bin/perl script.pl. Or just use plain calls - shebang would be ignored.

Special thanks to @Joshua and @ikegami

Upvotes: 2

elcaro
elcaro

Reputation: 2317

Do not replace system perl (or system binaries in general). You can build it to another location (as you suggested, /usr/local for example) and call it manually.

My personal preference is to use plenv. There's a nice guide here to get you started.

If you admin the server and other users are logging in an using your scripts, you'll want to build plenv somewhere outside your home directory (eg. /opt/plenv) and ensure that all users $PATH is prepended with the bin path of your new perl. Without digressing too much, this can be done in /etc/profile or even better to declare you custom profile mods in a custom profile script (eg. /etc/profile.d/custom.sh).

I would also suggest using a more portable shebang such as #!/usr/bin/env perl which will use whichever perl is in a users $PATH first. The only exception to this is cron jobs, which I typically always hardcode full paths. (This is a personal preference based entirely how I admin my boxes and probably not a good idea to recommend unless you know the full repercussions. Administering a server is entirely subjective based on it's use-case, your use-case likely differs vastly from mine).

Upvotes: 5

Related Questions