• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Source Digit

Source Digit

Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos

  • Home
  • How To
  • Ubuntu
  • Instagram
  • Blogging
  • Android
  • WordPress
  • +More
    • Cloud Computing
    • Gadgets
    • Social Media
    • Technology
  • Write for Us
Home / How To / How To Use ChatGPT In Terminal Ubuntu Command Line

How To Use ChatGPT In Terminal Ubuntu Command Line

By Sourabh / August 2, 2025 Category: How To, Ubuntu

Want to chat with ChatGPT directly from your command line? ShellGPT—a Python-based CLI wrapper for OpenAI’s GPT—makes it easier to use ChatGPT In Terminal Ubuntu command line.

With this tool users can seamlessly send prompts, generate shell commands, code snippets, documentation, and even chat interactively—all from their terminal.

Before getting started, make sure you have:

  • A Linux distribution (e.g. Ubuntu, Debian, Arch)
  • python3, pip3 (Recommended) python3-venv for creating isolated environments
  • An OpenAI API key (visit your OpenAI dashboard to generate one)

Step 1: Instal Python On Debian/Ubuntu:

sudo apt update -y
sudo apt install python3 python3-pip python3-venv -y

Step 2: Create and Activate a Virtual Environment

mkdir shellgpt && cd shellgpt
python3 -m venv venv
source venv/bin/activate

This keeps ShellGPT isolated from global Python packages—helpful for avoiding version conflicts.

Step 3: Install ShellGPT using Pip

Inside your activated venv:

pip install shell-gpt

This installs the sgpt CLI tool.

Step 4: Set Up Your OpenAI API Key

Temporarily export in your terminal:

export OPENAI_API_KEY="your_secret_key"

To make it persistent across sessions, add this line to your ~/.bashrc or ~/.zshrc, then run source ~/.bashrc:

echo 'export OPENAI_API_KEY="your_secret_key"' >> ~/.bashrc && source ~/.bashrc

Step 5: Use sgpt from the Command Line

You can run general queries and ShellGPT provides direct, human-like answers, saving you a web search:

sgpt "Where is Nginx default config file located?"

Users can also generate Shell Commands

sgpt --shell "Make all files in current directory read-only"

It will give you the following output:

chmod -R a-w .

Not only this, users can execute generated commands with confirmation and also generate code snippets

ShellGPT (sgpt) is a powerful CLI tool that embeds ChatGPT’s intelligence into your terminal. From generating code and shell commands to interactive chat, you can keep everything in your shell, speeding up development and operations.

CAUTION: Always review ShellGPT-generated commands before executing. Keep your API key private, and don’t share sensitive data via prompts.

Primary Sidebar

Latest Posts

How To Find Large Files And Directories In Linux Command Line

How To Use Clear Command History In Linux Terminal

Linux Command To Check RAM Size In Ubuntu Terminal In GB

How To Install Proprietary Drivers In Linux Ubuntu Using Terminal

How To Shutdown Linux With A 15 Minute Delay And Message

Free AI Courses With Certificate For Beginners In India

Best AI Plugins For WordPress To Use In 2026

3 Commands To Check USB Connection In Linux Terminal

Linux Terminal Commands for Beginners With Examples

How To Password Protect A Folder In Linux Command Line

© 2026 Source Digit • Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos

  • Home
  • About
  • Privacy Policy
  • Terms & Conditions
  • Contact Us
  • Sitemap