October 2014
M T W T F S S
« Mar    
 12345
6789101112
13141516171819
20212223242526
2728293031  
134

Refs

Categories

Archives

profile for slm on Stack Exchange, a network of free, community-driven Q&A sites

[one-liner]: Managing Multiple Installations of Perl in your $HOME Directory using Perlbrew

Background

If you’re a Ruby or Ruby on Rails developer then you’re most likely familiar with rvm. rvm is just one of those tools that once you get your head around and start to use, you’ll say “duh! Why didn’t I think of this earlier?”. Well I just found a similar tool for Perl. It’s called Perlbrew (App::perlbrew), and it works very similarly to rvm.

Now in case you’re not familiar with rvm, perlbrew allows you to manage multiple perl installations in your $HOME directory. Having this capability is huge. For example:

  • No need to run sudo to install CPAN modules, any more.
  • Try the monthly released new perls.
  • Learn new language features.
  • Test production code.
  • Leave vendor perl (the one that comes with OS) alone
  • Maintain completely isolated perl universes.

Solution

The installation is pretty much in line with rvm’s, mainly:

1
2
3
4
5
6
7
8
# via curl
% curl -kL http://install.perlbrew.pl | bash
 
# via wget
% wget --no-check-certificate -O - http://install.perlbrew.pl | bash
 
# via cpan
% sudo cpan App::perlbrew

Now you’re ready to initialize your installation area.

1
2
# Initialize
% perlbrew init

And here are some of the basic things you can do to manage your $HOME perl installations.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Pick a preferred CPAN mirror
% perlbrew mirror
 
# See what is available
% perlbrew available
 
# See full help
% perlbrew help
 
# Install some Perls
% perlbrew install 5.14.0
% perlbrew install perl-5.8.1
% perlbrew install perl-5.13.6
 
# See what were installed
% perlbrew list
 
# Switch perl in the $PATH
% perlbrew switch perl-5.12.2
% perl -v
 
# Temporarily use another version only in current shell.
% perlbrew use perl-5.8.1
% perl -v
 
# Or turn it off completely. Useful when you messed up too deep.
# Or want to go back to the system Perl.
% perlbrew off
 
# Use 'switch' command to turn it back on.
% perlbrew switch perl-5.12.2
 
# Exec something with all perlbrew-ed perls
% perlbrew exec perl -E 'say $]'
 
# Exec you program using all the perlbrew-ed perls
% perlbrew exec myprogram.pl

The primary command, perlbrew has the general form:

1
% perlbrew <command> [options] [arguments]

Finally, here’s the list of perlbrew commands:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# These are the <command> commands!
 
 init           Initialize perlbrew environment.
 
 install        Install perl
 uninstall      Uninstall the given installation
 available      List perls available to install
 lib            Manage local::lib directories.
 alias          Give perl installations a new name
 
 list           List perl installations
 use            Use the specified perl in current shell
 off            Turn off perlbrew in current shell
 switch         Permanently use the specified perl as default
 switch-off     Permanently turn off perlbrew (revert to system perl)
 
 self-upgrade       Upgrade perlbrew itself.
 install-cpanm      Install cpanm, a friendly companion.
 install-patchperl  Install patchperl
 
 mirror         Pick a preferred mirror site
 version        Display version
 help           Read more detailed instructions

For further information check out the main page and the CPAN page for perlbrew.

References

NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>