Tatsuhiko Miyagawa's Blog

plenv, alternative for perlbrew

August 12, 2013

plenv is to perlbrew what rbenv is to RVM.

If you’re satisfied with perlbrew there’s no reason that you must switch to plenv, but i did it earlier this year, and I’m happy with the switch.

Benefits

plenv is written entirely in bash (except perl-build, the part which downloads perl tarballs from PAUSE and apply patchperl), and provides “shims” in your PATH that locates the right executable of your perl and installed scripts, then calls exec on them.

That’s it, and there’s no magic shell functions that changes PATHs before running commands, nor your don’t need to switch perl from one to other, and later forgot that you’re running a wrong version of the perl in one shell.

plenv allows you to switch perl in 3 ways: PLENV_VERSION environment variable, .perl-version file in the current directory, then ~/.plenv/version global default settings.

PLENV_VERSION allows a quick run of your script with different perl without switching the version in your shell. But you can also export it to stick to the current shell if you want.

Per project .perl-version file will work great if you want to force the perl version among developers who all use plenv. This is a recommended setup if you use Carton, so all the developers are made sure to run the same version of perl.

Because all perl-based scripts (prove, plackup etc.) are also wrapped as shims, you have to run plenv rehash after installing CPAN modules that has scripts. But if you run plenv install-cpanm to bootstrap cpanminus, it will be automatically taken care.

Otherwise, cpanm (and CPAN.pm, CPANPLUS) just works like a normal perl installed in a user directory, and there’s no magic involved.

Installation

plenv used to be on CPAN, but now that its implementation is completely rewritten as a bash script, it’s not on CPAN anymore. This makes a benefit of not requiring a working CPAN client to install plenv.

I recommend the github checkout installation option in the README but you can also use homebrew if you’re on a Mac.

Hear more about plenv by the author, @tokuhirom on my podcast (in Japanese, audio auto-start).

Migration from perlbrew

Some people on Twitter expressed that they miss some of the features from perlbrew, such as use, lib and exec (plenv does have exec but does differently from perlbrew — which i think is more natural than perlbrew’s).

To demonstrate how simple and extensible plenv is, I implemented all of them as plugins at plenv-contrib. Hope this will make the transition easier if you missed these commands.