iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🏹

How to Install ag (The Silver Searcher) on CentOS, Ubuntu, and macOS

に公開
2021/11/19

Why I wrote this article

Note: This article is a reprint of this Qiita article by the author himself.

While "grep" is the go-to command for searching file contents, alternatives like "grab," "ack," and "ag" have emerged to speed up the process, and many people are making the switch.

Among them, I tried to install ag, which is rumored to be particularly fast[1], on CentOS 8 (virtualized with VirtualBox/Vagrant) by following the GitHub documentation with the commands below. However...

-- Results are the same with yum
$ sudo dnf update
$ sudo dnf install the_silver_searcher
-- The following error appears and installation fails
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:04:22 ago on Wed Nov 18 17:23:56 2020.
No match for argument: the_silver_searcher
Error: Unable to find a match: the_silver_searcher

Since it failed with the error shown above, I will outline the method that works below.
I will also perform the same process for Mac and Ubuntu.

Installing on Various OSs

CentOS 8

  • Version check
$ cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)
  • Installation
-- Two dependencies are listed in the README.md
$ sudo dnf -y groupinstall "Development Tools"
$ sudo dnf -y install pcre-devel xz-devel zlib-devel
$ cd /usr/local/src
$ sudo git clone https://github.com/ggreer/the_silver_searcher.git
$ cd the_silver_searcher/
$ sudo ./build.sh
$ sudo make install
-- Confirm that ag is installed
$ which ag
/usr/local/bin/ag

Ubuntu

  • Version check
$ cat /etc/os-release
-- Partially omitted
VERSION="20.04.1 LTS (Focal Fossa)"
  • Installation
$ apt update
$ sudo apt install silversearcher-ag
-- Confirm that ag is installed
$ which ag
/usr/bin/ag

*Note: For Ubuntu, I am using a native installation on a LENOVO ideapad 330S, not a virtual environment.

macOS

  • Version check
$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.7
BuildVersion:   19H15
  • Installation
$ sudo brew install the_silver_searcher
-- Confirm that ag is installed 
$ which ag
/usr/local/bin/ag

*Note: If Homebrew is not installed, please refer to this article for installation instructions.

In the future, I plan to write a brief article on how to use ag and compare it with grep when I have time. :rocket:
That's all for today.

References

脚注
  1. According to the author's personal experience, it is overwhelmingly fast, and there is information stating that it is 3 to 5 times faster than ack, which is already faster than grep. However, some disagree with this, and since I haven't conducted numerical verification myself, I cannot state it definitively here. Sorry about that. ↩︎

GitHubで編集を提案

Discussion