Perl on a Windows 7 laptop

I’ve been setting up my Windows 7 laptop to have as complete a Perl development environment as possible. I don’t have a choice about the operating system in this case, but I am used to the Unix-style environment, which I’d like to maintain.

One option is to use Cygwin and just dive into there for everything. However I do want some of my code to work natively under Windows so there is still a need to run Perl tests at a Windows console. I might as well develop there too, if I can. I’ve ended up with the following steps, which are in places bodgy hacks, but show the principle works at least:

  1. Git for Windows
  2. Strawberry Perl
  3. Vim fix
  4. Windows Console
  5. perldoc fix
  6. local::lib
  7. cpanm installer
  8. Local CPAN mirror

First thing is to install Git for Windows, known as msysgit (don’t alter any of the Windows PATH settings at install time). It’s a great little system which ships with Bash, Vim, and a suite of other handy tools. On this platform you probably want to set the End Of Line character(s) to ensure consistency. I have the following in my ~/.gitconfig:

    editor = vim
    eol = lf
    ui = true

The bundled Perl in msysgit is a little ancient (5.8.8). Download and install the excellent Strawberry Perl distribution. Our goal is to have perl within the msysgit environment be Strawberry Perl’s perl. Move C:\Program Files\Git\bin\perl.exe out the way (to perl-g.exe) and copy C:\strawberry\perl\bin\perl.exe in its place (there are no symbolic links under Windows).

By changing the Perl though, you knacker parts of Git which use Perl (for example git commit --interactive). The way to fix this is to keep a copy of the original msysgit perl (as above) and then edit any of the scripts in C:\Program Files\Git\libexec\git-core to have #!/usr/bin/perl-g at the top. Here’s a list:

  • git-add--interactive
  • git-svn
  • git-difftool
  • git-relink
  • git-send-email

The msysgit bundled Vim also needs some help, in the form of syntax files. I downloaded and installed GVim for Windows, and copied the .vim files from C:\Program Files\Vim\vim73\syntax to C:\Program Files\Git\share\vim\vim73\syntax but perhaps there’s a less brute-force way. At the least, you should get hold of perl.vim and pod.vim.

The Windows console program leaves a lot to be desired. I found a reasonable alternative in the form of Console2, an open source project hosted on Sourceforge. Download and install that (well, copy to Program Files). You’ll definitely want to edit its Settings so under Hotkeys, set Close tab and Rename tab to an alternative, or None (by doing Clear then Assign for each). Also under Settings in the Console section I set the Shell to be C:\Program Files\Git\bin\sh.exe --login -i and the Startup dir to be a folder I created in my user area for Perl development. Now, pinning the Console2 application to the Start Menu means it can be opened straight into msysgit’s Bash.

At the shell I installed my own vimrc file to ~/.vimrc, and created a ~/.bash_profile containing the following:

alias ll="ls -l --color"
alias view="vim -R"
export TERM=vt100

Strawberry Perl ships with many useful tools in its bin directory. Some of them are Windows batch files (.bat) because the expectatation is that you’re running Perl from the native Windows console. In this setup we’re within a Bash shell so they don’t work. One thing you’ll probably miss is perldoc, so create a ~/bin directory and in ~/bin/perldoc put the following:

require 5;
use Pod::Perldoc;
exit( Pod::Perldoc->run() );

I always use a local::lib area for the modules used in my development, and Strawberry Perl ships with this module. Simply run the llw32helper program from the normal Windows console and it’ll ask you for the new local::lib location then set Registry entries appropriately. One reboot later and perl -V should include this new library path.

From Strawberry Perl’s CPAN shell (perl -MCPAN -e shell) I only install one module - App::cpanminus. This provides a new tool, cpanm, for installing modules. Note that since the previous local::lib setup, App::cpanminus is installed to that location rather than Strawberry Perl’s standard library path.

The final step is to have a local CPAN mirror. This means I can work on the Windows 7 laptop from a remote part of a Scottish Hebridean island, for instance, fully off-line. This uses the CPAN::Mini and CPAN::Mini::Webserver modules, both installed via the cpanm utility. The minicpan command line app will create the mirror for you. The minicpan_webserver app fires up an interface at http://localhost:2963/. Here are example commands used with this setup, which I’ve made into Bash aliases (also set your ~/.minicpanrc as per the docs):

minicpan -l /path/to/local/minicpan -r
cpanm --mirror file:///C:/path/to/local/minicpan --mirror-only -v Module::Name

A remaining niggle is that cursor keys don’t seem to work in less (Ctrl-N and Ctrl-K are alternatives). I’ve not yet found a fix for this; however they do work in Vim. Another issue I found is that, bizarrely, cpanm sometimes fails unless the -v option is provided. Also with cpanm it seems more successful at unpacking dist tarballs when treating the local platform as UNIX rather than WIN32 so I hacked the script to do that. I wish I were more capable on this platform to begin to debug this (please email me if you want to collaborate).

That’s pretty much where I’m at, right now. I’d welcome constructive feedback on this process in the comments (at if you’re reading a syndication). My deep thanks and respect to all the developers of the above tools and libraries, who have made this possible.


The whole dance with replacing msysgit’s perl seems pointless to me. Wouldn’t it be much nicer to install msysgit such that only git.cmd is placed on the PATH and then install a separate msys or cygwin to get gnu tools on PATH?

If you’d consider ActivePerl, you wouldn’t need to remake perldoc, since, as far as i am aware, it always creates a perl/bat pair for things in bin dirs.

As for debugging: Look into Komodo IDE (not Edit). It has a visual line debugger which allows you to step through code instruction by instruction, inspect all variables in a nice treeview and even execute arbitrary code while at a breakpoint.

I recently created a screen cast on Installing Strawberry Perl I think having a really basic introduction on how to setup Perl on Windows is something we need.

I don’t use Windows, so your experience here is really interesting thanks for blogging.

I had Console2 recommended to me as well, seems odd that it won’t work for Perldoc - hopefully that can be sorted.

I’ll try do the next steps (local::lib + cpanm) next.

when you describe adding things to PATH, remember that this (registry twiddling to make it persistent) is all still a little magical to me!

I’ll try to explain. PATH is the same on windows as on Linux, an environment variable. Depending on where you are, it can either be the current environment, or the global setting. When i said “put things on PATH” i meant changing the global setting.

This can be done manually, by clicking Start → right-click Computer → Properties → Advanced system settings → Environment Variables → System variables → PATH (phew) (Note that on Win7 changes to this system setting are instantly available globally.)

HOWEVER, what i actually meant was: Let the installers handle that. Install Cygwin so you can call all the GNU stuff, like grep, from the normal windows command shell; install MSysGit using the second option, so only the git command is exposed; install AP/SP and you should be set.

I’d still prefer Strawberry Perl to ActivePerl as a personal preference.

They both have subtle differences. I just found for myself that AP plays nicer with my system. :)

Perhaps this is something which needs patching in Strawberry - that bin dir commands get non-.bat versions.

That would be a good idea. You could try poking Alias about that, as i believe he’s the one responsible.

Quite simple actually: The git.cmd sets up a temporary PATH for its execution so the git executable can find them, but the rest of the system doesn’t. :)

Leave a comment

About Oliver Gorwits

user-pic Computer Networks is my business, so Perl is my glue.