简体   繁体   中英

how do I install ack on OS X?

i did this once before, but have since forgotten how. i seem to remember having the ack.pl file in an "opt" directory close to root level on my Mac. i also remember that i will need to update my path settings in my ~/.profile or ~/.bash_profile , etc. I hope someone can fill in the blanks with some detailed instructions on how to do this properly.

  • please note that i would like to know how to do this WITHOUT using any 3rd-party software / package managers (Homebrew, MacPorts, etc.).

OK - found the answer myself. Here's how i did it on OS X 10.10 Yosemite (no "opt" directory, no messing w/ editing my $PATH in /.profile, etc.)...

1 - set permissions on the directory /usr/local/bin to have read/write access for everyone.

(chmod 777 from Terminal - or - command + i from Finder, and set all to "Read & Write")

2 - then run the following command from the Terminal...

curl http://beyondgrep.com/ack-2.14-single-file > /usr/local/bin/ack && chmod 0755 /usr/local/bin/ack

(obviously the path to the file on http://beyondgrep.com will change as they release newer versions, so update this adddress accordingly from information at - http://beyondgrep.com/install/

3 - change read/write permissions on /usr/local/bin back to 755 ("Read & Write" by "system" only, group "wheel" and "everyone" set to "Read only")

and that's it!

There are a couple options, but before those, you'll need to fire up Terminal.app (or iTerm.app if you use iTerm2) and cd to the directory you saved ack.pl (prbly cd ~/Downloads ) and do:

$ chmod a+x ack.pl

so it's executable. You can test that with:

$ ./ack.pl --version
ack 2.14
Running under Perl 5.18.2 at /usr/bin/perl

Copyright 2005-2014 Andy Lester.

This program is free software.  You may modify or distribute it
under the terms of the Artistic License v2.0.

If you don't get something like that output something is wonky with your download.

To make it available as just ack.pl (you can also rename it to just ack btw), you can do:

$ sudo mv ack.pl /usr/bin

which will put it in a location already in your PATH .

If you have other non-Apple command-line software tools installed, then you may have a /usr/local/bin already setup. You can test that with:

$ ls -ald /usr/local/bin
drwxr-xr-x  861 bob  admin  29274 Dec  9 15:44 /usr/local/bin

$ echo $PATH | grep -c /usr/local/bin
1

If you don't get something similar to both results, then you don't have a /usr/local/bin readily accessible (so you can skip the following mv ). If you do have something akin to both results, then you can just use that location by:

$ sudo mv ack.pl /usr/local/bin

(I'm only using sudo to avoid potential permissions issues, it may work fine w/o sudo for the /usr/local/bin move).

If neither of those are acceptable, then you can do:

$ mkdir ~/bin # it won't do anything bad if you already have one
$ mv ack.pl ~/bin

and then edit your .profile and add a line at the end with:

export PATH=~/bin:$PATH

Exit out of the terminal completely and go back in and you should be able to enter ack.pl at any shell prompt without prefix and it should run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM