74

I have never used Perl, but I am really impressed by the ack, which I would like to use for source code searching, etc.

Can anyone guide me of how to make use of this excellent library on Windows?

Nifle
  • 11,745
  • 10
  • 75
  • 100
rajesh pillai
  • 8,102
  • 7
  • 43
  • 60

9 Answers9

80

Start by installing perl http://strawberryperl.com/

Install App::Ack by typing (in a windows command shell)

C:\>cpan App::Ack

And undoubtedly this will prove useful http://learn.perl.org/

Nifle
  • 11,745
  • 10
  • 75
  • 100
  • 6
    Note that using strawberryperl's portable version the directory of strawberryperl must not include spaces, otherwise odd errors rise. – Ciantic Feb 16 '10 at 19:29
  • Protip: `cpanm(1)` is a lot easier to use than `cpan(1)`, and it's also available in Strawberry Perl. – bambams Mar 27 '15 at 16:45
38

Not all the tests pass on all versions of Windows. You can most likely get 100% functionality from ack even if the install tests fail. Here is the command to force installation if failing tests prevent a normal install:

perl -MCPAN -e "CPAN::Shell->force(qw(install App::Ack));"
Robert Wahler
  • 12,350
  • 3
  • 19
  • 11
  • 3
    Thanks, this let me actually get it installed! :D – Nick Knowlson Dec 15 '10 at 20:27
  • 1
    Or save yourself a lot of typing with `cpanm -f App::Ack`. Add `-n` to skip tests since they currently don't really pass anyway... Won't affect anything other than skipping them, saving you time, but also leaving you not knowing if they would have passed... – bambams Mar 27 '15 at 16:46
  • Thanks for the info that the tests don't pass, but the install is okay. I was looking for a tarball solution until I found this post, but this is much easier. – bballdave025 May 29 '18 at 23:28
34

If you already have msysgit installed, then you don't need to install Perl, because you already have a version. You just need to download the standalone version of ack and put it somewhere in your bash path1. You can then run ack from your msysgit bash prompt.

If you also want to be able to run ack from the Windows command prompt, then you will need to create a batch script somewhere in your Windows path2 with the contents:

@"C:\Program Files\Git\bin\perl" C:\path\to\ack-standalone.pl %*

(You'll obviously need to edit the paths above to match your msysgit installation and where you placed the ack script.)

1: I just stuck mine in the mysysgit bin directory: C:\Program Files\Git\bin\ack. This isn't the most sensible location for it, but it works.
2: Again, I just created the file ack.bat in the msysgit bin directory C:\Program File\Git\bin.

Rich
  • 7,348
  • 4
  • 34
  • 54
  • 5
    I simply dropped `ack-standalone.pl` in `C:\Program Files\Git\bin`, using the filename `ack` (without extension). After this, running `ack` from Git Bash worked. No batch files or modification to the path were required. – Grilse Apr 15 '13 at 09:16
  • 2
    @Grilse Yes, I do say that in my answer, (although I guess I could have worded it more clearly). The batch files and path modification are necessary if you want the script to run from within Windows's Command Prompt. (Which, also, I could have explained better.) – Rich Apr 15 '13 at 09:37
  • 1
    Well, if you would edit your answer to word this more clearly, that'd be awesome! – Grilse Apr 15 '13 at 11:39
  • @Grilse Done. (Better late than never!) – Rich Oct 15 '13 at 11:31
24

If you have cygwin installed, you can simply download the standalone version. Perl is installed with cygwin. Here are the steps:

$ vim .bash_profile

Remove the comments from the lines:

# if [ -d "${HOME}/bin" ] ; then
#  PATH="${HOME}/bin:${PATH}"
# fi

Load the changes:

$ source .bash_profile

Make a bin directory:

$ mkdir ~/bin

Download ack (from the homepage):

$ curl https://beyondgrep.com/ack-2.22-single-file > ~/bin/ack && chmod 0755 ~/bin/ack

Note: you will have to manually install curl as it doesn't come with cygwin by default.

Swoogan
  • 5,298
  • 5
  • 35
  • 47
  • 1
    The lines you commented out in `.bash_profile` are the lines that check `~/bin` exists before adding it to the path. Since you create a bin directory, the checks can remain and it will work (and **should** remain, in case the bin directory is ever removed). – crdx Apr 22 '13 at 09:48
  • 1
    After cygwin is installed, all 3 lines are commented out. As I indicate, you should remove the comments. I'm not sure why the middle line was missing the comment symbol, but I've edited it and added it back. – Swoogan Apr 24 '13 at 20:08
  • Nice stand-alone file solution. Thanks for also giving the information about the `PATH` and `.bashrc` – bballdave025 May 29 '18 at 23:30
20

You should also run the following command to enable color highlights: cpan Win32::Console::ANSI

Jay
  • 201
  • 2
  • 3
6

Nothing worked for me, until I went to the ack website and saw this.

enter image description here

And I ran the following command in cmd prompt:

choco install ack
h-rai
  • 3,636
  • 6
  • 52
  • 76
5

I had to force cpan to install App::Ack since some of the tests didn't pass:

C:\> cpan
cpan> force install App::Ack
cpan> q
Tom
  • 42,844
  • 35
  • 95
  • 101
1

Depending on how you feel about installing pre-built binaries from open source projects, you might also consider The Silver Searcher (ag). It's ack-compatible and faster than ack. It's also available on Linux from the repositories in recent distros.

http://blog.kowalczyk.info/software/the-silver-searcher-for-windows.html

Jim Hunziker
  • 14,111
  • 8
  • 58
  • 64
0

You can install ack via cpan:

install strawberry perl

run cmd as admin

install ack:

cpan> force install App::Ack

it should work from there, followed this guide: http://www.jeedo.net/how-to-install-ack-on-windows-10/

Worked without any hitches.