Use ChatGPT from the Command Line on Linux

Want to use ChatGPT on Linux without a web browser?

I took a look at Bavarder, a GTK ChatGPT app for Linux recently (note: this app also supports a number of other generative AI backends, fwiw). While it’s a well-made app that works well a few readers wondered what the point of using over the ChatGPT website was.

Enter, chatGPT-shell-cli. This, as its name should suggest, a command-line tool for asking ChatGPT questions or giving it tasks, and receiving the output right there, in the same terminal session.

Using ChatGPT from a terminal could be useful on say, a headless system when you need to find something out, or if your desktop session crashes and you’re left using a TTY, you can troubleshoot the issue.

It’s a bash script so works just about anywhere Linux does, though it makes use of both curl and jq so if your distro doesn’t come with those preinstalled, install them prior to trying this script.

Let’s take a look at some of the things this can do.

Use ChatGPT from a Terminal

Use ChatGPT from the Command Line on Linux
Ask it …anything, within reason

Obviously, being a ChatGPT CLI app, the key role of this script is to enable you to ask ChatGPT a question or query, set it a task, grammar check your writing (hi), or, y’know, probing its disembodied, artificially predictive soul.

You run the script (if it’s installed you just type chatGPT to run it) and enter a prompt. After a little but of thinking the script will return text. “Context” is enabled so you ask follow up questions, tell it refine or rephrase its output, and so on.

But it can do a few other neat things too.

Want to turn your text into art? Using this script you can — though, alas, you don’t get to see ingeniously rendered ASCII creations. Instead, the script generates the image from your description and ChatGPT gives you a link to view it in a web browser:

Use ChatGPT from the Command Line on Linux
Generate art from words using DALL-E

You can get ChatGPT to generate workable commands you can run on your Linux system.

To do this, run chatgpt then, for your prompt, enter command: followed by a description fo what you want to achieve. For example, command: convert example.mp4 to using ffmpeg sped up by 50 percent.

Hit enter, and et voila: it prints what you need with a prompt to run it:

Use ChatGPT from the Command Line on Linux
Get commands you can use

You can also set an initial prompt for ChatGPT. This allows you to make it answer according to specific conditions.

Run chatgpt -i "Your prompt conditions".

For example, if I run chatgpt -i "Answer every question as a pirate" ChatGPT will answer all my queries in pirate speak — oo-arr, me ‘arties!

Use ChatGPT from the Command Line on Linux
Make it speak like a pirate (or anything else)

Use your imagination here; get creative, be entertained. Naturally generate AI services such as this aren’t infallible and regularly produce convincing-sounding answers that are wrong. Assess everything it spits out, don’t treat it as a god, and remember: it’s just predictive text.

Install ChatGPT-Shell-CLI

You can download ChatGPT-shell-cli from GitHub. The project is free, open-source software, and should work with minimal effort on most major Linux distributions.

A handy one-line installer command is listed on the GitHub project page. This sets the app up and prompts you to add an OpenAI API key (see below):

curl -sS | sudo -E bash

Prefer traditional installation? Fedora and openSUSE users can install the app from a third-party COPR; while Arch users can get it from the AUR.

You do need an OpenAI API key to use this script — though don’t let it put you off.

Create a free OpenAI account to generate an API Key. Copy the key — you only get to see this once so save it somewhere — then edit your ~/.bash_profile file, add export OPENAI_KEY=your_key_here to the end, save, and restart your terminal session.

If that doesn’t work (it didn’t for me on Fedora) you can run export OPENAI_KEY=your_key_here in a terminal to use the API key for the duration of your session (i.e. until you close the tab/window).

Print Friendly, PDF & Email

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Server Status

Aradippou Chat 1 Chat 2 Larnaca Limassol Nicosia

Chat Links

Official Links.

1. Chat 1.
2. Chat 2.

Alternative Mirror Links.

1. KiwiIRC 1.
2. KiwiIRC 2.

Other Web Clients.

1. IrcCloud.

Recent Posts

Related Posts:



Super Club Radio

Mighty Deals


CyIRC Tweets

Scroll Up
Fatal error: Uncaught WMAC\JSMin_UnterminatedStringException: WMAC\JSMin: Unterminated String at byte 1180: "+o.accessToken}}).then(e=>{if(!e.ok)throw e;return e});return a.catch(e=>{console.error(`Failed to logout chatrix session. deviceId: ${o.deviceId}`)}),a}})(); in /home/bszucbfe/public_html/wp-content/plugins/clearfy/components/minify-and-combine/includes/classes/ext/php/jsmin.php:215 Stack trace: #0 /home/bszucbfe/public_html/wp-content/plugins/clearfy/components/minify-and-combine/includes/classes/ext/php/jsmin.php(157): WMAC\JSMin->action(2) #1 /home/bszucbfe/public_html/wp-content/plugins/clearfy/components/minify-and-combine/includes/classes/ext/php/jsmin.php(96): WMAC\JSMin->min() #2 /home/bszucbfe/public_html/wp-content/plugins/clearfy/components/minify-and-combine/includes/classes/class-main.php(375): WMAC\JSMin::minify('(function(){"us...') #3 /home/bszucbfe/public_html/wp-includes/class-wp-hook.php(310): WMAC_PluginMain->jsSnippetcacher('(function(){"us...', '/home/bszucbfe/...') #4 /home/bszucbfe/public_h in /home/bszucbfe/public_html/wp-content/plugins/clearfy/components/minify-and-combine/includes/classes/ext/php/jsmin.php on line 215