Monday, May 25, 2009

install perl module as non-root

perl Makefile.PL, make, make test, make install

The standard way to install a Perl module on Unix is to change into the directory that was created when you unpacked the .tar.gz file, and then type the following sequence of commands:

  perl Makefile.PL
  make
  make test
  make install


This will create a makefile for you, then compile the module, test it, and put it in the correct location for you. This requires that you are logged in as root, so that you can copy files to the Perl library directory, and various other places on your system where the installation will put files.

If you do not have root permissions on the machine where you want to install the module, such as if you wish to install a module in your home directory, just change one of those commands. Instead of

  perl Makefile.PL

type

  #perl Makefile.PL PREFIX=/path/to/where/you/want/it
  perl Makefile.PL INSTALL_BASE=/path/to/where/you/want/it

 make install

That will put all the files in that directory. In order to use modules that are stored in that location, you will need to add the following like to your Perl programs:

  use lib "/path/to/where/you/want/it/perl5"
and, yes, thanks for the comment, local::lib might be easier to install a new module.
  use local::lib "/path/to/where/you/want/it/perl5"

1 comment:

Matt S Trout (mst) said...

Why not just use local::lib to handle this for you?

-- mst (mst at shadowcat.co.uk)