Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Add DuckDuckGo Search to Your Linux Terminal

· 4 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

You can add DuckDuckGo search to your Linux terminal using a command-line tool like ddgr or by creating a simple alias or function that opens DuckDuckGo in your default browser. The quickest method is installing ddgr, which lets you search and open results directly in the terminal. This guide covers installing ddgr, using it, and setting up a fallback alias.

What You'll Need

  • A Linux system with an active internet connection.
  • Terminal access (Ctrl+Alt+T usually opens it).
  • sudo privileges to install packages (if not using a user-level install).

Step-by-Step

  1. Install ddgr – The easiest way is via your package manager. On Debian/Ubuntu, run: sudo apt install ddgr. On Fedora: sudo dnf install ddgr. On Arch: sudo pacman -S ddgr. If not available, install from source (see Tips).
  2. Verify installation – Run ddgr --version in the terminal. You should see a version number. If not, check your PATH or reinstall.
  3. Perform a basic search – Type ddgr linux terminal and press Enter. The terminal will display a list of search results with numbers. Use the arrow keys or type the number to open a result in your browser (default). Press q to quit.
  4. Open results in terminal (optional) – To view results as text without leaving the terminal, use ddgr -x for a text-only view. This is useful for quick lookups.
  5. Set a custom number of results – By default, ddgr shows 10 results. To show 20, use ddgr -n 20 linux terminal.
  6. Create a simple alias (optional) – If you prefer a shorter command, add an alias to your shell config file (e.g., ~/.bashrc or ~/.zshrc). Add this line: alias dg='ddgr'. Then run source ~/.bashrc (or restart terminal). Now dg search term works.
  7. Use a browser-based fallback (if ddgr fails) – If you cannot install ddgr, create a function that opens DuckDuckGo in your default browser. Add this to your shell config: function ddg() { xdg-open "https://duckduckgo.com/?q=$*" }. Then run source ~/.bashrc and use ddg search term.

Common Mistakes

  • Typing the command wrong – Ensure you use ddgr (with a 'g') not ddr or ddg (unless you created an alias).
  • Forgetting to update package lists – On Debian/Ubuntu, run sudo apt update before installing to avoid outdated package errors.
  • Using sudo unnecessarily – ddgr works fine as a normal user. Using sudo for searches is not needed and can cause permission issues with config files.
  • Assuming results open in terminal – By default, ddgr opens results in your web browser. Use -x for terminal-only viewing.
  • Not setting the browser – If ddgr cannot find your browser, set the BROWSER environment variable. For example, export BROWSER=firefox in your shell config.

Tips

  • Use quotes for multi-word searches – For exact phrases, wrap them in quotes: ddgr "linux terminal".
  • Search specific sites – Use site: in your query, like ddgr site:stackoverflow.com python.
  • Open the first result quickly – After a search, press 1 to open the first result immediately.
  • Install from GitHub if needed – If your distro lacks ddgr, you can clone it: git clone https://github.com/jarun/ddgr, then cd ddgr and run sudo make install. Requires Python 3.6+ and pip.
  • Use environment variables for defaults – Set DDGR_DEFAULT_BROWSER or DDGR_NUM_RESULTS in your shell config to avoid typing options each time.

Troubleshooting

ddgr: command not found – The package didn't install correctly. Reinstall with sudo apt install --reinstall ddgr (or your package manager's equivalent). If installing from source, ensure the binary is in your PATH (usually /usr/local/bin).

Results don't open in browser – ddgr uses xdg-open by default. Ensure xdg-utils is installed (sudo apt install xdg-utils). Alternatively, set the BROWSER variable as mentioned in Tips.

Search returns no results – Check your internet connection. Also, DuckDuckGo might be temporarily blocking automated queries; wait a few minutes and try again. You can also try ddgr --debug to see what's happening.

ddgr is slow – This is often due to network latency. Try increasing the timeout with ddgr --timeout 15 (default is 10 seconds).

Terminal shows garbled text – This can happen if your terminal doesn't support Unicode well. Set your terminal to UTF-8 encoding. In most modern terminals, this is default.

Frequently Asked Questions

Can I use DuckDuckGo without installing anything?

Yes, you can create a simple alias or function that opens DuckDuckGo in your browser, as shown in Step 7. That requires no extra software.

Does ddgr work with other search engines?

ddgr is specifically designed for DuckDuckGo. For other engines, look at tools like googler (for Google) or s (for many engines).

How do I change the number of results shown?

Use the -n option, e.g., ddgr -n 15. You can also set a default in your shell config by exporting DDGR_NUM_RESULTS=15.

Can I search in a specific region or language?

Yes, use ddgr -l en for English, or ddgr -r us-en for US English region. Check ddgr --help for all options.

Is ddgr safe to use?

Yes, it's an open-source tool that simply queries DuckDuckGo's HTML interface. It does not send your searches to any third party beyond DuckDuckGo itself.

Can I use ddgr in scripts?

Absolutely. You can pipe output or use ddgr --json to get results in JSON format for parsing. This is handy for automation.