Install Perl in your home directory with perlbrew

In my last article on Perl I was trying to explain how you can use local::lib to install your own set of Perl modules in your home directory. While the last versions of Mac OSX still ships with fairly old versions of Perl (currently 5.8.6 and 5.10), a better idea is to install a complete and more up to date distribution of Perl in your home directory.
The docs for perlbrew explain what needs to be done very clearly, but I'll shorten it up here for you anyway.

1. If you've had local::lib installed earlier, delete (rm -fr) ~/perl5 and ~/.cpan. You might want to backup ~/.cpan/CPAN/ first.

2. Remove the setting of local::lib variables in .cshrc, .bash_profile or equalient files. For me I commented out this line in my .bash_profile, so it looks like this:

# local::lib
#eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)

3. Close all terminal windows and restart terminal. In a new window execute these commands:

# curl -L | bash
4. After it's finished, put this line in your .bash_profile, and afterwards execute the same line in your shell so that the same variables get set in the current session:

source ~/perl5/perlbrew/etc/bashrc

5. As the 'perlbrew'  command is now available, install Perl version 5.12.3 by executing the following command:

perlbrew install perl-5.12.3

6. Its going to compile for a while, and when its finished, switch to the new version:

perlbrew switch perl-5.12.3

7. Verify:

espent-mac:~ espent$ perl -v
This is perl 5, version 12, subversion 3 (v5.12.3) built for darwin-2level

Now thats better. Since Perl is now in your home directory with all its environment vars set correctly, you will not need to install local::lib. Just put your old back into ~/.cpan/CPAN, and execute cpan -i App::cpanminus to get one step closer to complete recovery.

Last tweets

Follow tagestad on Twitter