Posted on
Artificial Intelligence

Artificial Intelligence Coding Assistants for Linux

Author
  • User
    linuxbash
    Posts by this author
    Posts by this author

Artificial Intelligence Coding Assistants for Linux: Supercharge Your Bash Workflow

If you live in the terminal, you already know the power of a well-crafted command. But you also know the pain: context-switching to docs, wrestling with arcane flags, or rewriting the same glue code over and over. AI coding assistants can meet you where you work—your Linux shell—and help you write, explain, and refactor code while staying fast and focused.

In this guide, you’ll learn why AI assistants are worth adding to your toolkit, and you’ll get practical, Linux-first instructions to install and use four proven tools that work great on Debian/Ubuntu, Fedora, and openSUSE. You’ll also see safe, real-world usage patterns you can adopt today.

Why AI in the Linux shell is worth it

  • Reduce friction for common tasks: Generate Bash one-liners, systemd units, or Dockerfiles without leaving your terminal.

  • Learn as you go: Ask for explanations of errors and unfamiliar commands, right in context.

  • Keep control: Use local models when privacy or offline work matters, or cloud models for highest-quality reasoning—your choice.

  • Improve code quality: Enforce best practices (set -euo pipefail, shellcheck hints, idempotent scripts) via prompts or templates.

What we’ll cover (and install)

We’ll set up and use four Linux-friendly assistants:

1) Shell-GPT (sgpt): Chat and “suggest a command” directly from your shell (pipx).
2) Aider: A Git-aware, terminal-first pair programmer that edits your repo via patches (pipx).
3) Ollama: Run modern LLMs locally on Linux with a single daemon.
4) GitHub Copilot in your terminal: The official GitHub CLI extension for suggestions and explanations.

Where we cite installation, we include apt, dnf, and zypper commands so you can copy/paste for your distro.

Tip: If you don’t have pipx yet, install it first (see below). Using pipx keeps tools isolated and easy to upgrade or remove.


Prerequisites you’ll likely want

  • Git and curl

  • Python 3 and pipx (for CLI tools installed via Python)

  • Optional: GitHub CLI (for Copilot in your terminal)

Install core prerequisites:

# Debian/Ubuntu
sudo apt update
sudo apt install -y git curl python3 python3-pip pipx || sudo apt install -y git curl python3 python3-pip
python3 -m pip install --user pipx
python3 -m pipx ensurepath

# Fedora
sudo dnf install -y git curl python3 python3-pip pipx || true
python3 -m pip install --user pipx
python3 -m pipx ensurepath

# openSUSE (Tumbleweed/Leap)
sudo zypper refresh
sudo zypper install -y git curl python3 python3-pip pipx || true
python3 -m pip install --user pipx
python3 -m pipx ensurepath

After installing pipx, start a new shell or source your shell profile so ~/.local/bin is on PATH.


1) Shell-GPT (sgpt): “What’s the command for that?”

Shell-GPT gives you a chat-like interface and can output safe, copy-pastable commands. It’s great for “What’s the rsync flag for…?” or “Explain this docker error.”

Install via pipx:

pipx install shell-gpt

Configure your provider:

  • For OpenAI:
export OPENAI_API_KEY="sk-...your key..."
# Optionally add to your shell profile:
echo 'export OPENAI_API_KEY="sk-...your key..."' >> ~/.bashrc
  • For OpenRouter (multi-model brokerage):
export OPENROUTER_API_KEY="or-...your key..."
echo 'export OPENROUTER_API_KEY="or-...your key..."' >> ~/.bashrc

Usage examples:

# Ask for a one-liner (sgpt prints a command; review before running)
sgpt "find all .log files modified in the last 24 hours and tar.gz them to /tmp/logs.tar.gz"

# Explain an error message in plain English
dmesg | tail -n 50 | sgpt "explain these kernel messages"

# Turn a description into a script template (with safety flags)
sgpt "write a robust bash script that syncs ~/data to /mnt/backup with rsync, set -euo pipefail, logs to syslog"

Safety tip: Ask sgpt to include “set -euo pipefail” and “shellcheck-friendly” in its prompts.


2) Aider: A Git-savvy pair programmer in your terminal

Aider reads your repository context and proposes patch sets as diffs. You keep control by reviewing/applying changes. It can talk to OpenAI, Anthropic, and local models via Ollama.

Install via pipx:

pipx install aider-chat

Optional providers:

# OpenAI
export OPENAI_API_KEY="sk-..."; echo 'export OPENAI_API_KEY="sk-..."' >> ~/.bashrc

# Anthropic
export ANTHROPIC_API_KEY="sk-ant-..."; echo 'export ANTHROPIC_API_KEY="sk-ant-..."' >> ~/.bashrc

# Local models via Ollama (see section 3)
export AIDER_OLLAMA_MODEL="llama3.1:8b"

Use it inside a Git repo:

cd /path/to/your/repo
git init && git add . && git commit -m "baseline"  # if new
aider .

Example sessions:

# Ask aider to add a feature with tests; it proposes diffs, you approve
aider . --message "Add a --dry-run flag to backup.sh, ensure idempotency, and include set -euo pipefail. Write a bats test."

# Use a local model via Ollama
AIDER_OLLAMA_MODEL="llama3.1:8b" aider . --message "Refactor script/install.sh to support apt, dnf, and zypper with clear error handling."

Why it’s great for Linux users:

  • Review patches before they touch your tree

  • Tight Git integration

  • Works online or fully local with Ollama


3) Ollama: Run powerful LLMs locally on Linux

Prefer to keep code private or work offline? Ollama runs modern models locally and exposes a simple CLI and HTTP API. It pairs nicely with Aider and editor plugins.

Install Ollama (official script):

curl -fsSL https://ollama.com/install.sh | sh

Start and pull a model:

# Run the service (usually auto-starts post-install)
ollama serve &

# Try a capable general-purpose model
ollama pull llama3.1:8b
ollama run llama3.1:8b

Ask code-specific questions:

ollama run llama3.1:8b "Write a POSIX-compliant Bash function to retry a command with exponential backoff"

Use as a local endpoint from tools:

  • In Aider: set AIDER_OLLAMA_MODEL="llama3.1:8b"

  • In editors (VS Code/Neovim) via Ollama-compatible plugins

Note: Ollama does not use apt/dnf/zypper; the cross-distro script above is the recommended method. It installs and manages its own service/binaries.


4) GitHub Copilot in your terminal (gh extension)

If you already use GitHub, Copilot’s terminal integration can suggest commands, generate scripts, and explain errors through the official GitHub CLI.

Install GitHub CLI:

# Debian/Ubuntu
type -p curl >/dev/null || sudo apt install -y curl
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update && sudo apt install -y gh

# Fedora
sudo dnf install -y 'dnf-command(config-manager)'
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install -y gh

# openSUSE
sudo zypper addrepo https://cli.github.com/packages/rpm/gh-cli.repo gh-cli
sudo zypper refresh
sudo zypper install -y gh

Install and use Copilot extension:

gh auth login                         # authenticate to GitHub
gh extension install github/gh-copilot

# Generate a Bash snippet
gh copilot suggest -t "Create a portable bash script that compresses ~/logs by date, keeps last 7 archives, and prints a summary"

# Explain a command or error
gh copilot explain --command 'sed -n "5,10p" file.txt'

Tip: Pipe logs or compiler output to Copilot “explain” for quick diagnostics.


Real-world workflows you can adopt today

1) Safe “review then run” pattern

# Let AI draft, but you decide when to run:
sgpt "one-liner to remove dangling Docker images without touching running containers"
# paste the suggested command, inspect it, then run it

2) Bake quality into scripts

sgpt "Write a shellcheck-clean, POSIX-compliant script with set -euo pipefail that syncs ~/data to /mnt/backup, retries, and logs to syslog"

3) Upgrade a repo with Aider

aider . --message "Introduce Makefile targets: lint (shellcheck), test (bats), and package. Update README with usage for apt, dnf, zypper."

4) Go local when privacy matters

ollama pull llama3.1:8b
AIDER_OLLAMA_MODEL="llama3.1:8b" aider . --message "Refactor deploy.sh to detect distro and install dependencies with apt/dnf/zypper."

5) Keep secrets safe

# Store API keys in your shell profile and avoid committing them
echo 'export OPENAI_API_KEY="sk-...your key..."' >> ~/.bashrc
echo 'export ANTHROPIC_API_KEY="sk-ant-...your key..."' >> ~/.bashrc

Troubleshooting quick hits

  • Command not found after pipx install? Ensure ~/.local/bin is on PATH:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc
  • SSL or proxy issues? Set environment variables:
export HTTPS_PROXY="http://proxy.example:8080"
export HTTP_PROXY="http://proxy.example:8080"
  • Model quality too low locally? Try a larger model or switch to a cloud provider for that task, then return to local for routine edits.

Conclusion and next steps

AI coding assistants don’t replace your shell skills—they amplify them. Start simple: install sgpt for quick command help, add Aider for safe refactors in your repos, run Ollama when you want privacy or offline capability, and bring Copilot into your terminal if you’re already in the GitHub ecosystem.

Your next step:

  • Pick one tool and install it now:

    • sgpt: pipx install shell-gpt
    • Aider: pipx install aider-chat
    • Ollama: curl -fsSL https://ollama.com/install.sh | sh
    • GitHub Copilot (terminal): install gh via apt/dnf/zypper, then gh extension install github/gh-copilot
  • Add a small win to your day: generate a safe script template, explain an error, or refactor a utility with tests.

  • Iterate: tune prompts, standardize best practices, and decide when to use local vs. cloud models.

Have a favorite Linux-first AI workflow? Share it—and the prompt that made it click.