Installing Perl modules on UNIX w/o root permissions
- March 30th, 2006
- Write comment
Installing Perl modules on a UNIX virtual server when you don’t have root or administrator privledges.
Before you begin: In order to install modules, you have to have SSH or Telnet access to the server. If you don’t have this access (or you don’t know what SSH/Telnet means) then you’ll probably have to get your system administrator to install modules for you.
I recently wanted to install the DBD::CSV module on my virtual host server (UNIX FreeBSD) and found that it was more challenging than I would have liked. I’m not positive I have the best approach, but it did work for me in the end. Following are the steps that I had to take to get the module and all those on which it depends installed. The primary problem is that on the virtual server, I don’t have root/administrator privledges. So, I have to install Perl modules in an alternate directory. The scripts have to be altered to point to that directory as well.
To install my beloved DBD::CSV, I notice that I also have to have all of the following modules installed and working:
DBI
File::Spec
Text::CSV_XS
SQL::Statement
So, we will install those first, then finally install DBD::CSV.
First, I set up MCPAN. This is a Perl utility that automatically downloads, unpacks, compiles and installs Perl modules. Since I don’t have root, I was only able to utilize MCPAN for the downloading and upacking part. I still had to compile and install the modules manually. If you don’t have access to, or don’t want to bother with MCPAN, then you can just download the modules directly from http://www.cpan.org and unpack them yourself.
To run MCPAN, you enter something like this (this will start the process of installing DBI, the first required module):
perl -MCPAN -e 'install DBI'
The first time I ran this utility, I was automatically taken through an installation process. A directory ~/.cpan was created in my home directory and I was prompted with several questions. I simply used all the defaults. There was only one question that I had trouble with, which was something like “What is your favorite CPAN mirror.” This seemed to be asking where to look for downloadable modules. I wish I remembered what I put, but it took me several tries to find one that worked. I finally wound up entering a server in Japan, which I’m sure is not good. But it worked. You might check for possible server locations here: http://www.perl.com/CPAN
Anyway, after running that the first time, the DBI module installation files were saved in ~/.cpan/build/DBI-1.14. (in case you don’t know ~/ usually means your home directory), however the installation failed because it tried to write some stuff to the main Perl installation location and, again, I don’t have permission to write there. however, when you are manually installing modules, I do know that you can specify an alternate directory. So, I went into the ~/.cpan/build/DBI-1.14 directory and manually installed it like so:
cd ~/.cpan/build/DBI-1.14
perl Makefile.PL INSTALLDIRS=site INSTALLSITELIB=/usr/www/users/myaccount/cgi-bin/lib
make
make test
make install
When I installed it, I see that I got a few errors and such. Upon closer inspection, it seems that the POD documentation and other stuff is still trying to go in the main Perl library location. I ignore these errors, since it doesn’t seem to effect anything but the documentation. Obviously, you want to replace /usr/www/users/myaccount/cgi-bin/lib with the location on your server where you want to save the modules.
Anyway, now I try the File::Spec module:
perl -MCPAN -e 'install File::Spec'
cd ~/.cpan/build/File-Spec-0.82
perl Makefile.PL INSTALLDIRS=site INSTALLSITELIB=/usr/www/users/myaccount/cgi-bin/lib
make
make test
make install
That one was easy. I still got errors, but I just ignore them. Now I try Text::CSV_XS:
perl -MCPAN -e 'install Text::CSV_XS'
cd ~/.cpan/build/Text-CSV_XS-0.21
perl Makefile.PL INSTALLDIRS=site INSTALLSITELIB=/usr/www/users/myaccount/cgi-bin/lib
make
make test
make install
Same old thing. More errors. Moving along to SQL::Statement…
perl -MCPAN -e 'install SQL::Statement'
cd ~/.cpan/build/SQL-Statement-0.1016
perl Makefile.PL INSTALLDIRS=site INSTALLSITELIB=/usr/www/users/myaccount/cgi-bin/lib
make
make test
make install
Another one bites the dust. The final one, DBD::CSV is more tricky because when I tried the same thing, it doesn’t work. I can’t do the Makefile.PL part of it because it says I am missing some required modules. What is happening is that the installer is looking in the standard Perl path – however we have been installing all of our goodies to an alternate location and Perl doesn’t know about it. My solution is that I simply comment out the lines in Makefile.PL where it checks for all the required modules! That’s a crappy way to do it, but it works.
perl -MCPAN -e 'install DBD::CSV'
cd ~/.cpan/build/DBD-CSV-0.1024
Now I edit Makefile.PL and comment out these lines (about 20 lines down from the top or so)
# $ok &&= CheckModule('DBI', '1.00');
# $ok &&= CheckModule('Text::CSV_XS', '0.16');
# $ok &&= CheckModule('SQL::Statement', '0.1011');
That’s it. the rest is the same.
perl Makefile.PL INSTALLDIRS=site INSTALLSITELIB=/usr/www/users/myaccount/cgi-bin/lib
make
make test
make install
All done at last! I tried my script and it worked just fine. One adjustment that you might have to make to your script is to add the location of your libraries to your script. You do this by putting the location in a BEGIN clause in your script like so:
BEGIN {
unshift(@INC,"/usr/www/users/myaccount/cgi-bin/lib");
}
Put this at the top of your script before any other subroutines or anything. That tells your script to look there when loading modules. Since you use the “unshift” function, your path is added to the front of the list. If you would rather your script look in the regular places first, and look in your custom path last, then you can use “push” instead of “unshift.”
One final thing. I went into ~/.cpan/build/ and deleted all the files and folders. I get charged for disk space overusage, so no use keeping all those installation files, right?