Search code examples
windowsripgrep

How to install ripgrep on Windows?


How do I install ripgrep (rg) on Windows?


Solution

  • I've had to start developing on Windows again recently, and have had a hard time figuring this out.

    So, here's what I've come up with:

    Tested in Windows 10 Pro and Windows 11 Pro.

    First, install Git for Windows.

    Then, open up the Git Bash terminal which comes with it. You should run all commands below in Git Bash unless stated otherwise.

    The super-short, quick answer:

    Open Git Bash as an admin, and run:

    # install ripgrep
    choco install ripgrep
    # verify it is now installed
    rg --version
    

    If you don't have choco (Chocolatey) installed, you can install it by running this as an admin in PowerShell:

    Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
    

    Source: https://chocolatey.org/install

    Other, non-admin installation options, and more details, are below:

    [No admin privileges required] Option 0: use scoop instead of choco

    See my comment on how to install via scoop (instead of choco) in a non-admin PowerShell terminal!:

    Note that installing rga (ripgrep-all) also installs rg (ripgrep):

    Instructions to install rga via scoop

    1. Install scoop: in a non-admin PowerShell, run:

      Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
      Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
      

      Source: https://scoop.sh/

    2. Install rga via scoop: in a non-admin PowerShell, run:

      # Install rga (ripgrep-all)
      scoop install rga
      
      # Install fzf too while we are at it
      scoop install fzf
      

      Source: https://github.com/phiresky/ripgrep-all?tab=readme-ov-file#scoop

    Now it works!

    [More versatile, and does not require admin privileges] Option 1: how to manually install ripgrep (or any executable, for that matter) on Windows

    This manual process is pretty much the same on Linux or Windows (except that Git for Windows is needed only on Windows), and can be used for any executable file or script.

    Go to the ripgrep releases page here, and find the URL of the executable you want from the latest release. For 64-bit Windows, use either the GNU-compiled version (ripgrep-13.0.0-x86_64-pc-windows-gnu.zip), or the MSVC-compiled version (ripgrep-13.0.0-x86_64-pc-windows-msvc.zip). I tested both and they both run fine. Note that the GNU-compiled rg.exe file is larger at around 38.2 MB, however, and the MSVC-compiled rg.exe is about 4.42 MB. I don't know why there is such a huge difference but I'm guessing it's because the MSVSC-compiled version is relying more on existing Windows dynamic libraries already available in the system.

    In the instructions below, I used ripgrep-13.0.0-x86_64-pc-windows-msvc.zip. Adapt the instructions accordingly if you use a different file.

    # download the latest 64-bit Windows release file of your choosing (GNU or
    # MSVC)
    curl -LO https://github.com/BurntSushi/ripgrep/releases/download/13.0.0/ripgrep-13.0.0-x86_64-pc-windows-msvc.zip
    # unzip it
    unzip ripgrep-13.0.0-x86_64-pc-windows-msvc.zip
    
    # create a ~/bin dir to store it
    mkdir -p ~/bin 
    
    # copy rg.exe into ~/bin
    cd ripgrep-13.0.0-x86_64-pc-windows-msvc
    cp -i rg.exe ~/bin/
    

    Now, create and edit your ~/.bashrc file:

    # Create `~/.bashrc` if it doesn't exist, or just update the access and
    # modification time of the file if it does.
    touch ~/.bashrc
    # Open the file in your editor of choice. Examples:
    notepad ~/.bashrc  # in Notepad
    nano ~/.bashrc     # in Nano
    subl ~/.bashrc     # in Sublime Text
    code ~/.bashrc     # in Microsoft Visual Studio Code (MS VSCode)
    

    Add this to the bottom of the ~/.bashrc file you just opened (this is borrowed from Ubuntu's default ~/.profile file, which I've put online here):

    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
        PATH="$HOME/bin:$PATH"
    fi
    

    Finally, close and reopen all Git Bash terminals, or run this in all of them that are open:

    # re-source your ~/.bashrc file to update your PATH
    . ~/.bashrc
    

    Now test to see that rg (ripgrep) works:

    # check the version number
    rg --version
    

    My run and output is:

    $ rg --version
    ripgrep 13.0.0 (rev af6b6c543b)
    -SIMD -AVX (compiled)
    +SIMD +AVX (runtime)
    

    [Easier, but requires admin privileges] Option 2: how to install ripgrep (or other programs) via a package manager such as choco in Windows

    Quick summary:

    Press your Windows key --> type in "Git Bash" --> right-click your Git Bash shortcut --> click "Run as administrator". In this Git Bash window running as administrator, run the following commands:

    # Install ripgrep in Windows.
    # See: https://github.com/BurntSushi/ripgrep#installation. Apparently my
    # computer already has `choco` installed on it. 
    choco install ripgrep
    # - then follow the on-screen instructions, typing `y` for "yes", 
    #   or `a` for "yes to all", when needed
    
    # verify that ripgrep is installed; I see:
    #       
    #       ripgrep 13.0.0 (rev af6b6c543b)
    #       -SIMD -AVX (compiled)
    #       +SIMD +AVX (runtime)
    #       
    rg --version
    

    While you're at it, you might as well install fzf and bat too, since my rgf2.sh script (see: here and the installation instructions at the top of rgf.sh) requires both of those:

    choco install fzf  # install fuzzy-finder
    choco install bat  # install colored `cat` ("cat with wings")
    

    Close the Git Bash admin window when done, and go back to using a non-admin Git Bash window.

    Details

    I am very accustomed to using apt or snap to install programs in Linux Ubuntu.

    It turns out that there are 3 popular package managers in Windows too:

    1. Chocolatey: choco install ripgrep
      1. Very popular.
      2. It has some paid versions, but there is also a free (as in freedom) and open source, and no-cost, version for both individuals and companies/organizations as well. See: https://chocolatey.org/pricing.
        1. Looking in my directory at C:\ProgramData\chocolatey\LICENSE.txt, I see that the open source license they use is the Apache License, Version 2.0, which I believe is a very non-restrictive (generous) license.
    2. Scoop: scoop install ripgrep
    3. Winget (see also here): winget install BurntSushi.ripgrep.MSVC
      1. This is an official, Microsoft-supported app.

    In Git Bash, check to see if you already have these tools installed. I already had choco and winget installed. I'm not sure why or how I already had them installed, but maybe they came with Windows, or with Git for Windows. See if they are installed on your system:

    choco --version   # I see `1.3.0`
    scoop --version   # I see: `bash: scoop: command not found`
    winget --version  # I see: `v1.5.1572`
    

    Let's use Chocolatey to install ripgrep, since I've read it may be the most popular and have the most programs on it.

    1. Install it See: https://chocolatey.org/install.

      Run this in your Power Shell only if you do not already have choco installed:

      Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
      
    2. Then, use it:

      Open up Git Bash as an administrator, and run:

      choco install ripgrep
      rg --version  # check the version to see if it installed correctly
      
    3. Close the Git Bash admin window when done, and go back to using a non-admin Git Bash window.

    References

    1. I first discovered the 3 main Windows package managers, Chocolatey, Scoop, and Winget here and here.
    2. My own answer on how to use curl (the -L part of my curl usage above is required, as GitHub had an HTML 302 redirect for the download link of the ripgrep release)

    Going further

    1. To mass search a ton of PDFs at once with ripgrep, install ripgrep-all, or rga, here: https://github.com/phiresky/ripgrep-all

      In short:

      choco install ripgrep-all
      
    2. My comment on how to install via scoop (instead of choco) in a non-admin PowerShell terminal!