Do you want Artificial Intelligence to complete your Linux command? If yes, then try out ShellGPT, which, with the help of ChatGPT can complete your Ubuntu Terminal commands. You don’t need to remember complex commands of Linux, just ask the Chatbot to run them for you.
What is ShellGPT?
ShellGPT is an open source command line tool for Linux that uses ChatGPT to generate shell commands, code snippets, comments, and to perform AI chat, among other things using terminal.
It is developed by a community of developers and the project’s source is available on the GitHub page of ShellGPT. The reason behind developing this tool is to help users who prefer the command line and don’t want to do Google searches for solving different problems. This eventually saves a lot of time, especially if you are a new Linux user.
With the help of a brief description of the Shell commands or scripts you want, the tool will perform the task effortlessly. Also, being an open source tool, anyone can use ShellGPT free of cost and can contribute too. Its community-driven development process also ensures the project is up-to-date with the latest developments in the field.
For example, you can want to know the default Nginx path on your Ubuntu or any other Linux. Then just ask ShellGPT and it will give you an exact answer with the path. Another example, suppose you want to create a Docker container running with an Apache web server and with 80 or 443 ports of container mapped to host ports. Then just ask ShellGPT to do that.
Further, this AI for Shell commands uses the GPT-3.5 language model. One of the unique features of it, it can understand natural language input and provide context-aware suggestions for Shell commands.
Being an open-source tool, ShellGPT is flexible and customizable, which means users can fine-tune its behavior and output to suit their needs.
If you are still confused, then don’t be in this article we learn all that how to install ShellGPT and use it to perform various tasks on our Linux system.
Use ChatGPT in the Ubuntu Linux terminal
The tool here we will use is based on Python, hence this tutorial is not just limited to Ubuntu only, even Linux Mint, AlmaLinux, Rocky, Fedora, Debian and other Linux users can perform the steps given here to get ChatGPT in their Linux terminal.
1. Start with the Ubuntu update
Although here we are going to use PIP, a Python package manager, however, it is good practice to start with the system update command. This not only installs the latest available security package but also rebuilds the APT package manager index cache. So, run:
sudo apt update && sudo apt upgrade
2. Check whether Python3 is available or not
ChatGPT is built on Python and so is ShellGPT, therefore we need to have Python language installed on our Linux system if we want to use this command line tool. In all the latest Ubuntu systems, especially desktops, Python version 3 will be installed already. So, let’s first check whether it is on our system or not.
You will have an output, something like the below:
If there is no output, then it would be not installed on your system. Therefore, to get it run the given command:
sudo apt install python3
3. Install Pip Package Manager
Developers of ShellGPT made it available through the PIP, which is a popular package manager of Python to manage various dependencies and libraries required by apps written in Python. However, unlike Python, PIP is not available by default on the Ubuntu Linux system and we need to install it manually. So, here is the command to do that.
sudo apt install python3-pip
To check the version and confirm it is on our system, use:
4. Generate OpenAI API key
ShellGPT itself cannot do anything it is just a medium to bring OpenAI’s ChatGPT features to your Linux terminal. Therefore, we need an API (Application Programmable Interface) key. It let the Terminal use the ChatGPT through your OpenAI account, whether it is free or has paid subscription, doesn’t matter.
Note: OpenAI offers an $18.00 free credit to use the API key. Once it exhausted the free request quota then the user needs to pay $0.03 / 1K tokens.
So, here are the steps to generate the OpenAI API key to use it in Linux Terminal:
- Visit the Open AI Website
- You will see Login and Sign up buttons.
- Those who already have an OpenAI account, can simply press the Login button and enter the login details or use the social mediums available to sign in. Whereas, the rest of the new users need to create an OpenAI account using the Signup link.
- Once, you logged-in, from the left side menu – select the API keys given under the USER area.
- You will see the API keys page of OpenAI.
- Now, hit the Create new secret key button.
- A pop-up will appear with your generated API Key. Just copy that and move to the next step.
5. Install ShellGPT (ChatGPT) for Linux Terminal
Now, to use ChatGPT on the Linux terminal, just run the given command of PIP that will install ShellGPT on our Linux system along with the packages it requires to work properly. Not only installation even to get future updates and uninstallation of ShellGPT can be done using PIP.
pip install shell-gpt --user
–user option is to tell the “pip” to install ShellGPT in the Python user directory i.e typically ~/.local/
Wait for a few seconds, this AI command line tool will be on your Linux system.
4. Add ShellGPT to your Linux path
Once the installation is completed, add the ~/.local/bin in your system’s path, so that it can execute the binary of SGTP available inside the BIN folder from anywhere in the Terminal regardless of which directory we currently are on our command line.
Edit Bashrc again:
At the end of the file, paste the following line:
Save the file by pressing Ctrl+X and then Y followed by the Enter key.
Source the newly updated Bashrc file to apply the changes you have done in it.
To check it is working, you can run:
But you will get an API key missing error. To remove that move to the next step.
6. Add API Key to ShellGPT Configuration file
By default, the tool will create a configuration file to control the behavior of ShellGPT. We edit this file to add the API key we have generated.
Add the beginning of the file add:
Replace the “your-API-key” with the exact OpenAI APY key you have generated. And to save the file use, Ctrl+X, press Y, and hit the Enter key. See the screenshot for an idea:
7. ShellGPT Available Options
sgpt --option "command to complete the task"
|–temperature||FLOAT RANGE [0.0<=x<=1.0] Randomness of the generated output. [default: 1.0]|
|–top-probability||FLOAT RANGE [0.1<=x<=1.0] Limits highest probable tokens (words). [default: 1.0]|
|–chat||TEXT Follow the conversation with id (chat mode). [default: None]|
|–show-chat||TEXT Show all messages from provided chat id. [default: None]|
|–list-chat||List all existing chat ids. [default: no-list-chat]|
|–shell||Provide shell command as output.|
|–execute||Will execute –shell command.|
|–code||Provide code as output. [default: no-code]|
|–editor||Open $EDITOR to provide a prompt. [default: no-editor]|
|–cache||Cache completion results. [default: cache]|
|–animation||Typewriter animation. [default: animation]|
|–spinner||Show loading spinner during API request. [default: spinner]|
|–help||Show this message and exit.|
8. Use ChatGPT in Ubuntu Linux Terminal
Finally, you will have the ShellGPT on our Linux system, now let’s run a few commands to check how it works. Here are some examples:
The command line tool for ShellGPT is “
1. Ask it to show the amount of free RAM on your system
Let’s ask our Linux terminal to list the complete details of the system RAM.
sgpt --shell --execute "list free hard disk space and RAM on this system"
in short, you can use
sgpt --se "list free hard disk space and RAM on this system"
You will see the ShellGPT will not only give you the commands that can be used to fetch the RAM info but will ask for your permission to execute it.
2. How to create Docker Container using ChatGPT?
If your system has Docker installed then we can use the ChatGPT to create a Docker container, for example, you want to create an APACHE container with exposed ports 80 & 443. Then no need to Google and search the command syntax to do it.
Just ask the ChatGPT and it will do that for you.
sgpt -se "start Apache using docker, forward 443 and 80 port, mount current folder with index.html"
3. Start Chatting with SGPT
To chat with ChatGPT to ask about various things or write some essay you can use it without any option.
sgpt "what is LinuxShout"
Linux Command Terminal with ChatGPT – Last note
In this way, you can ask various questions or can make the ChatGPT to complete your task on Linux. For information, you can visit the GitHub page of this ShellGPT tool.
Although ShellGPT is a great way to utilize the power of ChatGPT in Linux commands, that provides an easy way to learn Linux commands for beginners and even for experienced users to save time. With its natural language processing abilities users don’t need to remember complex commands.
However, as ShellGPT depends upon the API key of OpenAI which is paid, therefore after the free trial users need to pay if they want to keep their LINUX terminal to be Smarter and not just merely a command line screen. Chatting with an AI becomes possible directly from within our terminals without ever leaving it. We hope this article has helped explain how easy it is for anyone using Linux to install and use ChatGPT.
Yes, we can run ChatGPT on Linux Terminal or graphically using various open source projects one such is ChatGPT Desktop Application, and another one we already have discussed in this article i.e ShellGPT.
Install Python on your system and run
pip install shellgpt or go to our article that describes the steps to run ChatGPT GUI on Linux.
There is a ShellGPT command line tool available on GitHub, we can use that to run the ChatGPT on the Linux Command line.
ChatGPT itself doesn’t have access to the internet however, the users who are accessing it as a Chatbot need Internet access on their system. In short, yes we need an Internet connection on mobile or PC.