Installing a Perl module is not a genius’ work, but getting it done without root access can be a challenging task (of course not impossible). You may face this situation when you do not have rights to standard directories where a Perl module is installed. In this tutorial we will see how we can install a Perl module without root or super user permission by installing it in separate non-standard directories.
Before we proceed, let’s make a few things clear. First of all, I am assuming that you have Perl installed on your system. Apart from that, I’ll be using the following directories to install the Perl module:
/home/perl_modules/bin /home/perl_modules/man /home/perl_modules/man/man1 /home/perl_modules/lib
You can create these directories (bin, man, man/man3 and lib) anywhere you want. We will use that path in the Perl configuration. You should replace the path used in the tutorial to your own directory path.
Now we need to define some variables to configure Perl locally. These configuration will be used to tell the Perl module where it should be installed. To do that, I would suggest that we write all those variables in one file and then use it while installing. It will save us time and effort in writing the lengthy commands and will be good for future use.
Let’s say we create a file “perl_local_config” in /home directory (the file can be created wherever you want):
Now let’s edit this file to set the configuration variables. Write the following variables in it:
PREFIX=/home/perl_modules \ INSTALLSCRIPT=/home/perl_modules/bin \ INSTALLBIN=/home/perl_modules/bin \ INSTALLMAN1DIR=/home/perl_modules/man1 \ INSTALLSITELIB=/home/perl_modules/lib
Download the Perl module from the CPAN (or from wherever you want). Unzip it. Go into the module directory. Now, the standard steps of installing a Perl module is:
perl Makefile.PL make make test make install (if all tests are successful)
Since you do not have root access, the perl Makefile.PL will give error. And here comes the local configuration file to our rescue. Run these commands one by one:
perl Makefile.PL `cat /home/perl_local_config`
If the Perl module depends upon other Perl module then the above command will generate error. In that case, download and install the modules on which it is dependent. Same procedure, which we are discussing here, would be followed.
make make test
All tests should pass successfully.
When running the Perl module may generate error like this:
Can't locate Locale/Recode.pm in @INC (@INC contains: XXXXX......XXXXX) at /home/bin/your_perl_module line XX.
That means that Perl is looking for your module in standard lib directory and not the one where you have installed it. To solve this error, add the locally created lib directory (/home/perl_modules/lib in the example) to the library path like this:
Do change the paths with your own directory path.
I hope that the tutorial was easy to understand and simple to follow. I also hope that you are now able to install Perl modules locally, without super user privileges, like a champ now. I would appreciate your feedback. Do subscribe to newsletter if you found the tutorial helpful and want to stay in touch for more updates. Enjoy :)
Receive the latest update in your inbox.