Add DuckDuckGo Search to Your Linux Terminal
In this article
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
- 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). - Verify installation – Run
ddgr --versionin the terminal. You should see a version number. If not, check your PATH or reinstall. - Perform a basic search – Type
ddgr linux terminaland 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). Pressqto quit. - Open results in terminal (optional) – To view results as text without leaving the terminal, use
ddgr -xfor a text-only view. This is useful for quick lookups. - Set a custom number of results – By default, ddgr shows 10 results. To show 20, use
ddgr -n 20 linux terminal. - Create a simple alias (optional) – If you prefer a shorter command, add an alias to your shell config file (e.g.,
~/.bashrcor~/.zshrc). Add this line:alias dg='ddgr'. Then runsource ~/.bashrc(or restart terminal). Nowdg search termworks. - 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 runsource ~/.bashrcand useddg search term.
Common Mistakes
- Typing the command wrong – Ensure you use
ddgr(with a 'g') notddrorddg(unless you created an alias). - Forgetting to update package lists – On Debian/Ubuntu, run
sudo apt updatebefore 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
-xfor terminal-only viewing. - Not setting the browser – If ddgr cannot find your browser, set the BROWSER environment variable. For example,
export BROWSER=firefoxin 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, likeddgr site:stackoverflow.com python. - Open the first result quickly – After a search, press
1to 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, thencd ddgrand runsudo make install. Requires Python 3.6+ and pip. - Use environment variables for defaults – Set
DDGR_DEFAULT_BROWSERorDDGR_NUM_RESULTSin 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.