14

First, some background.

perlbrew is a tool to assist with the installation of Perl into a non-standard directory (usually under your home directory).

It also helps you control which Perl installation is used when executing perl in an interactive shell. Switching between installations is done using perlbrew use and perlbrew switch. perlbrew use only affects the current shell, while perlbrew switch is more permanent.

$ perl -V:version             |  $ perl -V:version
version='5.20.0';             |  version='5.20.0';
                              |
$ perlbrew use 5.18.2t        |  $ perlbrew switch 5.18.2t
                              |
$ perl -V:version             |  $ perl -V:version
version='5.18.2';             |  version='5.18.2';
                              |
$ bash -ic 'perl -V:version'  |  $ bash -ic 'perl -V:version'
version='5.20.0';             |  version='5.18.2';

perlbrew off is used to revert to using the system Perl, but it's temporary like perlbrew use. Is there a way to revert to the system Perl with the permanency of perlbrew switch?

ikegami
  • 367,544
  • 15
  • 269
  • 518
  • 2
    wow, you are really fast at answering your own question :) – jh314 Aug 07 '14 at 17:28
  • @jh314, It's an SO feature. When you ask a question, there's a checkbox labeled something like "answer your own question". If you check that, an answer form appears. Both the question and the answer are submitted simultaneously. – ikegami Aug 07 '14 at 17:30
  • Cool, didn't see that! So you ask when you know the answer? – jh314 Aug 07 '14 at 17:36
  • 6
    @jh314 SO's purpose is to build a database of useful Questions and Answers. It's just as useful to share things one learns on their own using this method, yes. Especially if it's a very specific question and therefore easily searched for. – Miller Aug 07 '14 at 17:37

2 Answers2

26

To have perlbrew manage an installation of perl that wasn't installed by perlbrew, pick a name ("system" in my example) and create a link to its bin directory as follows:

cd "${PERLBREW_ROOT:-$HOME/perl5/perlbrew}"
mkdir perls/system
ln -s /usr/bin perls/system/bin

It will now appear in perlbrew list

$ perlbrew list
  ...
  system (5.10.1)
  5.18.2t
* 5.20.0t
  ...

And you'll be able to use perlbrew use and perlbrew switch.

$ perl -V:version
version='5.20.0';

$ perlbrew switch system

$ perl -V:version
version='5.10.1';

$ bash -ic 'perl -V:version'
version='5.10.1';

This works best with installations that have the same installbin, installvendorbin (if applicable) and installsitebin directories, as returned by

perl -V:'install.*bin'

By the way, a similar approach can be used to create aliases for perlbrew installs. For example,

 ln -s 5.26.1 perls/5.26           # Point to the latest release of a version.
 ln -s 5.26.1 perls/project_name   # Point to the install used by a project.
ikegami
  • 367,544
  • 15
  • 269
  • 518
  • 1
    I followed these instructions and after running `perlbrew switch system` I got: "A sub-shell is launched with system as the activated perl. Run 'exit' to finish it." That doesn't seem permanent... – Marcus Mar 03 '19 at 12:11
  • 1
    @Marcus, You have an improperly installed `perlbrew`. See [this](https://stackoverflow.com/q/11194041/589924) – ikegami Mar 03 '19 at 18:49
  • Ah, nice. Thank you @ikegami. – Marcus Mar 04 '19 at 03:10
2

You can use the following command

perlbrew switch-off
Sadok
  • 36
  • 2
  • `switch-off` wasn't always part of `perlbrew`, but this is clearly the better solution now :) The technique used by the other answer is still valuable to integrate other `perl` builds not installed by `perlbrew`, however. – ikegami Mar 11 '20 at 21:52