ChatGPT in the Terminal on Linux
How to run ChatGPT and AI from your Linux shell — the first-party CLI, the raw API, and community tools.
Running ChatGPT in the terminal on Linux is easier than it used to be. The first-party route is OpenAI's Codex CLI, a coding agent you run right in your shell. Other options include calling the OpenAI API with curl or using a community CLI like shell-gpt.
This guide walks through each route with exact install and usage commands. It also clears up a common mix-up: the viral "act as a Linux terminal" prompt does not run in your real shell. It only makes ChatGPT pretend to be one inside a chat window.
By the end, you will know which tool fits your workflow. You will also know the one install mistake that trips up most first-time users.
The Quick Answer: Which Tool to Use
The fastest way to get ChatGPT in the terminal on Linux is OpenAI's Codex CLI. It is the official tool, it signs in with your ChatGPT account, and it can act on files in your project.
Your choice depends on what you want. Pick a coding agent, a raw scripting call, or a lightweight chat helper.
Here is a short comparison to help you decide.
- Codex CLI (first-party): best for coding tasks and agent-style work in a repo. Signs in with your ChatGPT or OpenAI account.
- Raw OpenAI API with curl: best for scripts, automation, and full control. Needs an API key and pay-per-use billing.
- shell-gpt (community): best for quick one-line questions and shell command help. Third-party, so vet it before you install.
Want help using ChatGPT and AI from the Linux terminal across your team? Layer3 Labs can set it up.
Book a ConsultationOption 1: OpenAI Codex CLI (the First-party Way)
Codex CLI is OpenAI's official terminal tool, and it is the main answer for developers. It is a coding agent that runs in your shell, reads local repos, and can make edits.
It works on Linux and macOS. On Windows, you run it through WSL. You install it once, then call it from any project folder.
There are two main install paths. Both are quick.
- npm install:
npm install -g @openai/codex(needs Node.js 18 or later). - Standalone installer (no Node needed):
curl -fsSL https://chatgpt.com/codex/install.sh | sh - Homebrew is also available on supported systems.
- Verify it worked:
codex --version
Signing in and Running Codex
After install, you sign in with your ChatGPT or OpenAI account. Run codex and it prompts you to sign in. Older docs mention a codex auth command.
You can also authenticate with an API key if you prefer. Once signed in, you point Codex at a task in plain language.
In our own work wiring coding agents into developer workflows, the most common setup mistake we see is developers installing the wrong package and then assuming Codex itself is broken. Check the scoped name first.
For the full Linux install walkthrough, including troubleshooting, see our dedicated Codex CLI guide linked below.
- Start it:
codex(run inside your project folder). - It can run Codex in local repos, read local files, and propose edits.
- Codex CLI now also ships inside OpenAI's official ChatGPT desktop app for Linux.
Option 2: Call the OpenAI API with Curl
If you want full control, call the OpenAI API directly. This is the most flexible route because you script every request yourself.
You need an API key from your OpenAI account and a payment method, since API use is billed per token. Store the key in an environment variable, never in a public file.
Here is a basic request you can adapt.
- Set your key:
export OPENAI_API_KEY="sk-..." - Send a request:
curl https://api.openai.com/v1/chat/completions \-H "Authorization: Bearer $OPENAI_API_KEY" \-H "Content-Type: application/json" \-d '{"model": "gpt-5.6", "messages": [{"role": "user", "content": "Explain tar flags"}]}'
Option 3: Community CLIs Like Shell-gpt
Community tools wrap the OpenAI API in a friendly command. shell-gpt (the sgpt command) is a well-known one. It is built for quick questions and shell command suggestions.
These tools are third-party. They are not made by OpenAI, and quality varies. Treat them as a category, not a single blessed tool.
Before you install any community CLI, check the GitHub project. Look at stars, recent commits, and open issues to confirm it is active and safe.
- shell-gpt gives fast, one-line answers and can suggest shell commands.
- Most community CLIs need your own OpenAI API key and use pay-per-token billing.
- Vet any project first: recent commits, maintainer activity, and issue history.
The "Act as a Linux Terminal" Myth
A popular prompt tells ChatGPT to "act as a Linux terminal." This does not run ChatGPT in your real shell. It only makes the model pretend to be a terminal inside a chat.
When you type a command in that chat, ChatGPT prints made-up output. Nothing runs on your machine. No files change and no programs execute.
This is fun for demos and learning. It is not a way to run real commands. For that, you need Codex CLI, the API, or a community CLI from the sections above.
A Newer Option: The Official ChatGPT Linux App
On August 11, 2026, OpenAI launched an official ChatGPT desktop app for Linux in public preview. It bundles the Codex coding agent alongside the chat interface and a built-in web browser.
This is useful context for terminal users. If you install the app, you get a Codex agent without a separate CLI setup. The app can run Codex in local repos and read local files.
The app is a public preview, so OpenAI warns it may contain bugs. For a pure terminal workflow, the standalone Codex CLI is still the lightest choice.
- The Linux app ships as
.deb(Debian/Ubuntu) and.rpm(Fedora) packages. - It includes ChatGPT, ChatGPT Work, the Codex agent, and a built-in browser.
- Download it from OpenAI's official ChatGPT download page.
How to Choose and Get Started Today
Most Linux developers should start with Codex CLI. It is official, quick to install, and built for real work in your projects. Install it with npm or the standalone script above.
Reach for the raw API when you are scripting or automating. Reach for a vetted community CLI when you just want fast answers in the shell.
Whatever you pick, running ChatGPT in the terminal on Linux comes down to three routes: the first-party Codex CLI, the OpenAI API, or a community tool you have checked. Start with Codex CLI and expand from there.
Frequently Asked Questions
- Install OpenAI's Codex CLI. Run `npm install -g @openai/codex` (Node.js 18+) or `curl -fsSL https://chatgpt.com/codex/install.sh | sh`. Then verify with `codex --version` and sign in with your account.
- Yes. Codex CLI is OpenAI's first-party terminal tool. It is a coding agent that runs in your shell, reads local repos, and can make edits. It is the main first-party answer for developers.
- You likely installed the unscoped `codex` package, which is an unrelated 2012 project. Always install the scoped `@openai/codex` package instead. This is the single most common install mistake.
- Yes. Use the standalone installer: `curl -fsSL https://chatgpt.com/codex/install.sh | sh`. OpenAI now ships an official standalone installer that removes the Node.js dependency. Homebrew is also an option.
- No. That prompt makes ChatGPT simulate a terminal inside a chat window. It prints made-up output and runs nothing on your machine. To run real commands, use Codex CLI, the API, or a community CLI.
- Call the OpenAI API with curl. Set your key as an environment variable, then POST to the chat completions endpoint. This is the most flexible route for automation. Check current model names and pricing in OpenAI's docs first.
- shell-gpt is a community project, not an OpenAI product. It can be useful, but you should vet it first. Check the GitHub project's stars, recent commits, and open issues before installing, since it handles your API key.
- Codex CLI signs in with your ChatGPT or OpenAI account, and some features may require a paid plan. Raw API and most community CLIs use pay-per-token billing, so you need an API key and a payment method.
Put AI to work in your team's workflow
Layer3 Labs helps teams wire ChatGPT, Codex, and other AI tools into real developer and business workflows. Book a free AI workflow audit and we will map the fastest wins for your stack.
Book a Consultation