OpenAI’s ChatGPT is a powerful language model. ChatGPT’s capacity to recognize and create human-like writing offers up new opportunities for interactive discussions and information retrieval. In this post, we will look at how you can use ChatGPT straight from your Linux terminal, giving you a flexible AI assistant at your disposal.
Table of Contents
What Is ShellGPT for Linux?
ShellGPT is a command line version of ChatGPT that allows users to interact with the AI chatbot directly from their Linux terminal. It is based on OpenAI’s GPT big language model (for more information on OpenAI’s latest GPT-4 model, see here).
ShellGPT can provide intelligent suggestions and recommendations depending on your text input, and it can even run shell commands. It also learns from your interactions and improves with time. Users no longer need to input long instructions or memorize difficult Linux Terminal commands with this ChatGPT utility baked into the command line.
ShellGPT, like other artificial intelligence-enabled programs, is written in Python. While Python is normally installed by default on most Linux distributions, you may check its version information to see if it is installed. If Python isn’t already installed on your PC, you must do so before proceeding.
To verify Python’s version, open a terminal and enter the following commands:
Now that Python is installed on your system, you may install PIP, Python’s native package management.
Despite the fact that PIP is normally pre-installed with the Python bundle, it is best to verify the version beforehand to determine the condition of its installation. To see if it is installed on your PC, use the following command:
sudo apt-get -y install python3-pip
Once installed, use the following command to verify the Pip version on Linux:
Install and Set Up a Virtual Environment Using Python
Now that Python and PIP are installed, you may configure Python’s virtual environment to prepare the computer for installing and executing ShellGPT. Because they minimize library conflicts, virtual environments are great for executing isolated programs.
You may use a virtual environment to prevent interactions between your system’s and virtual environment’s applications while executing distinct executions in silos.
Install the venv module to establish a virtual environment in Python:
sudo apt install python3-venv -y
Set up the Environment.
Now that you’ve covered the prerequisites, let’s set up the environment for accessing ChatGPT from your Linux terminal using the following steps:
1. To begin, launch the terminal from the app’s menu or use the “Ctrl + Alt + T” keyboard shortcut.
2. Now, use the command below to create a new directory and arrange all of the files.
For example, we used the following command to create a new directory called “commandline-chatgpt”:
3. Use the “change directory” command to navigate to the new directory you just created:
In the following example, we’ve navigated to the commandline-chatgpt directory, where we’ll set up the environment to utilize ChatGPT in the Linux terminal:
4. Now, use the venv module to establish a virtual environment with the command below. The name “chatgpt_cli” was chosen for our virtual environment.
python3 -m venv <virtual_environment_name>
5. By default, the virtual environment you just established will be inactive. Use the following command to activate the environment:
When you run the mentioned command, the shell prompt will display the name of the virtual environment in brackets, as seen below:
Get Your OpenAI API Key
You must link the OpenAI services and your Ubuntu computer to execute ShellGPT now that the virtual environment is ready. You must first go to the OpenAI website and register an account there.
If you already have an account, log in and browse to your profile image, which is placed on the upper right-hand side of the page.
Click View API Keys, then Create new secret key.
This key should not be shared with anybody since the connection is private and should only be utilized on your system.
Because you won’t be able to review the same API key again, copy it from the dialog box and store it elsewhere.
To connect to your Ubuntu system, use the export command to create an environment variable:
Add and Verify the API Key into a Virtual Environment Variable
When you execute the API key in this manner, Linux will use it only for a single instance. However, if you want to make the execution permanent, save it in the .bashrc file.
All you have to do is type in the first command and enter the subsequent command within the text editor:
nano ./bashrc export OPENAI_API_KEY=<paste key details here>
Save your work and quit the editor. Then, use the source command to make the changes.
Finally, use the
env command to validate the API key.
Install ShellGPT on Ubuntu
Once the installation is complete, you may proceed to the ShellGPT installation. The installation procedure is simple, and the utility may be installed with the following command:
pip3 install shell-gpt
Also read: ChatGPT iOS App: A Powerful AI Chatbot for Your Mobile Device
This article is to help you learn about how to use ChatGPT in a Linux Terminal. We trust that it has been helpful to you. Please feel free to share your thoughts and feedback in the comment section below.
Leave a Reply