Mar 20

Compile your own perl in a custom directory

Category: Linux,Perl   — Published by tengo on March 20, 2008 at 2:58 am

This procedure is useful when your shared hosting webserver is running an outdated version of perl but your applications need a newer version; for example when utf8 functionality is needed which only newer versions fully support.

First read this small paragraph: http://www.bugzilla.org/docs/2.22/html/nonroot.html
Then get the latest perl sources and extract/configure/compile it:

$ wget http://perl.com/CPAN/src/stable.tar.gz
$ tar zvxf stable.tar.gz
$ cd perl-5.8.8 (replace with your perl version)
$ sh Configure -de -Dprefix=/path/to/your/future/own/perl
$ make (should run ok)

finally type make test (which might end with lots of errors, single hung-up texts can be stopped with [CTRL]+[C])

Then try to do make install, nevertheless
If your compile runs throught, you can use your freshly compiled perl as the base of your scripts, but remember that this is a non-standard perl and you can't use the standard shebang line #!/usr/bin/perl at the head of your code. Instead you need to to this:

#!/path/to/your/perl/binary/perl

Also, installing packages needs special treatment. Cpan runs with this code:

/path/to/your/perl/binary/perl -MCPAN -e 'shell'

Please note:

Your own perl also uses its own lib library. Thus, when you start your own perl in your scripts by using the modified shebang line, this binary should also use the relative path for libs - so you won't need to define the lib path in your scripts.

Just be sure, when you start cpan the first time and it asks the configuration questions, that you tell cpan, when it asks for PREFIX=~/perl, where your perl is located (the path!, not the binary):

/path/to/your/perl/dir

To tidy up your system, you can also let cpan write its temp files ".cpan" into this directory.