Installing Perl Modules on MS Windows Servers (the Easy Way)
This article explains a bit about the process of installing Perl modules and why the typical instructions found in a module’s ReadMe file do not work on Windows servers. If you want to skip all of the details and just get to the installation part, skip to Option 1
Before you begin: In order to install modules, you have to have access to the DOS prompt on the server. If you don’t have access to the DOS prompt (or you don’t understand what this means) then you will probably have to ask your system administrator to install the modules for you.
The Problem:
Do these lines look familiar to you:
perl Makefile.PL
make
make test
make install
Of course, you’ve seen them in the ReadMe file for a Perl modules that you want to install on your Windows server. However, when you get to line 2 and try to “make” the module, you get a “Bad command or filename” error. (If your Windows PATH is not set right, you might not even get past line one!) You look a little deeper into the ReadMe and see that, oh yes, for Windows machines you might have to say “nmake” or “dmake” instead. Still, the results are the same - or you get a bunch of errors. Why is this? Well, the authors of Perl mods often don’t use Windows at all, so they don’t really bother to tell you some important details. In fact, they secretly want you to install Linux instead, so they purposely make it tough on you!
Important Detail:
The ReadMe file mentions the command “make” as if it will just magically work. However, “make” is not a standard DOS command. (It’s actually not even a standard UNIX command) It is a utility program that comes with a C compiler. Although you can get C compilers from a number of places, Windows does not come with one pre-installed. So, you can type “make” until your fingers get blisters, but it won’t do you any good.
Hey, I thought I was programming in Perl - why do I need a C compiler, you ask? Good question. The first reason is that this is simply a familiar way for UNIX admins to install software, even though there may not even be any code to compile. The second reason is that some Perl modules make system calls or other low-level stuff that is not available using pure Perl code. So, they write a some of the code in C to go along with the Perl module. You may already know that C code needs to be compiled into binary form for each specific operating system. It’s not possible for the module author to provide pre-compiled versions for every operating system known to man. So, they just give you the C source code instead and let you compile it yourself for your own particular system. This is no big deal for most UNIX admins because, as I mentioned, this is a familiar way to install software. In fact, UNIX comes with a C compiler all set up and ready to use.
For Windows administrators though, this procedure is probably unfamiliar. Windows software typically comes pre-compiled, so there is no need to compile it. Windows doesn’t even have a C compiler built-in, so you have to buy or download one on your own. It is possible that you are a Windows NT guru and have set up umpteen gigantic corporate networks without ever once compiling a single program.
The good news, holmes, is that you have 4 (count ‘em, 4) options for installing modules on windows. The bad news is that there is no garauntee that any of them will work! Some modules were programmed on UNIX machines and never tested on Windows. They may not even compile correctly on Windows at all without code modification. Hopefully this is not the case for your module, but be prepared to either just accept it, or get really involved in porting that module to Windows!
Option 1
Option 1 is to download nmake.exe from Microsoft, run the executable (which will extract 3 files) and save these 3 files in your Windows directory. Next, download UNIX Utilities for Windows and extract all the files. Locate tar.exe, gunzip.exe and gzip.exe and copy them to your Windows directory as well.
Now your machine is ready to do some mod installing! At this point you should be able to follow the regular Perl module installation instructions, except where it says “make” you type “nmake” instead. Cross your fingers and hope that the module installs properly!! If it does, you’re all set. If not, move on to Option 2 and hope for the best…
Option 2
Option 2 is to use the MCPAN feature that is built into Perl. To do that, you need to have already done Option 1, because MCPAN still requires nmake to be installed on your machine. so, at the command line, you type:
perl -MCPAN -e "YOUR::MODNAME"
(substitute “YOUR::MODNAME” with the name of the mod you’re installing, of course) The first time you run this utility, it will ask if you are ready to continue with the manual configuration. Unless you know your networking stuff pretty well, i’d just hit No at this point and let Perl auto-configure it for you. After that it will attempt to load the module from CPAN and install it. It will look for required modules and try to install those for you as well.
Option 3
Option 3 is actually easier than Option 1 and 2, but only if you have installed ActiveState Perl ( http://www.activestate.com/ ). ActiveState Perl is a nice Windows port and it includes a utility called PPM which is used to install modules. The modules that PPM supports have been compiled for windows and uploaded to the ActiveState module repository. (Note: If you installed Indigo Perl, they created a browser based interface for installing modules which is really nice - check the docs for that). For this step, you do NOT need to have done Option 1 because PPM used pre-compiled modules - you don’t have to compile them yourself. That is one nice feature if Option 2 is crashing during the compilation process.
To use PPM, just go to the DOS command line and type “PPM” (without the quotes). You will be at the PPM command promt. (I should mention that you need to be connected to to the Internet at this point).
At the PPM promt, enter “install YOUR::MODNAME” - you will be prompted if you want to continue. At that point, PPM will connect to ActiveState and see if the module you requested is available in a pre-compiled form. If it is, it will install the module and you are all done! PPM is especially nice because it will even install other required modules for you.
If you get an error message that the module was not found, then it’s not available from ActiveState. You’re once again out of luck. Try Option 1 and 2 if you did not already. Otherwise move to Option 4.
Option 4
Option 4 is a kind of last resort that may not really work. Basically, some modules force you to go about all the MakeFile business, but in reality it is merely one or more .pm files. If this is the case, you can often just copy the .pm file(s) to your C:\Perl\Lib or C:\Perl\Site\Lib directory. Make sure you maintain the directory structure, for example Crypt::RC4 would be saved in C:\Perl\Site\Lib\Crypt\RC4.pm. So you might have to create some sub-directories to maintain the structure.
That’s It!
Share This