Have you ever found yourself delving deep into the world of Linux, longing for the wit and wisdom of an AI chatbot right there in your trusted terminal? Well, fear not, because ShellGPT is here to accompany you on this digital journey. By seamlessly integrating the capabilities of ChatGPT into your Linux Terminal, ShellGPT transforms into your virtual assistant, ready to provide insightful answers and clever suggestions, and even generate commands and code for you. Whether you’re a developer, writer, or researcher, Shell-GPT offers a seamless experience for crafting text-based content.
In this guide, we’ll walk you through the various steps of the installation process step by step.
Installation
Before proceeding with the installation, ensure that the system is up to date and that the packages: python3, pip3, and python3-venv are installed on your system. If not, you can install them using the following commands:
For Ubuntu/Debian:
sudo apt update -y
sudo apt install python3 python3-pip python3-venv -y
For Centos/RedHat-based OS:
sudo yum update -y
sudo yum install python3 python3-pip python3-venv -y
Virtual Environment for Shell GPT:
Creating a virtual environment isn’t strictly necessary but is highly recommended, especially for Python projects. It helps manage dependencies, versions, and packages in an isolated setting without affecting global Python settings on the Linux server. This practice ensures that your project has all its requirements contained, making it easier to manage and replicate across different machines or setups. For applications like ShellGPT, using a virtual environment can prevent conflicts between the tool’s dependencies and those of other Python projects on the same system.
To create and activate a virtual environment for this project, execute the following command:
mkdir sgpt && cd sgpt && python3 -m venv sgpt && source sgpt/bin/activate
Now, your prompt will be changed to the newly created virtual environment.
Acquiring an OpenAI API Key:
An API key is required for setting up Shell GPT on your Linux, and this can be set up by configuring your OpenAI/ChatGPT account’s API to the ShellGPT.
Steps to create an API key:
- To create an API key from OpenAI and utilize it on your ShellGPT, start by heading to the OpenAI website: https://platform.openai.com/docs/overview on your browser and signing up or logging in.
- Once logged in, move the cursor to the left side tab, and look for the API key section in the resulting menu. Click on API Keys and then click “Create secret key” in the next window.
- Give a name for the key and generate a new API key. When you create a new key, be sure to securely copy and save it immediately, as it will only be displayed once for security reasons.
Setting API and Environment Variables in Linux:
After successful API key extraction from OpenAI add it as an environment variable in the .bashrc
file, this is by executing the following command. (Remember to replace “your api key
” in the command with your actual OpenAI API key before running the command.):
echo 'export OPENAI_API_KEY=your api key' >> ~/.bashrc
Execute the command source ~/.bashrc
to run the new environment variable we set in .bashrc file
.
source ~/.bashrc
To enter again into virtual environment use the command: source sgpt/bin/activate
Installing Shell-GPT (Final Step)
The prerequisites for getting ready for installing Shell-GPT will be ready by now. Now go ahead with installing Shell-GPT:
pip3 install shell-gpt
After installation, verify whether Shell-GPT is installed or not via executing the below command:
sgpt --version
If successful, this command should display the installed version of Shell-GPT like this:
Running Shell-GPT
Shell-GPT commands offer versatility and control over text generation directly from your terminal. Whether you’re crafting stories, poems, or summaries, the prompts you enter allow you to tailor the output to your needs. Utilize the shell-gpt
command followed by the prompt you wish to generate text for.
sgpt "Your Prompt Here"
Parameters that can be used with sgpt commands:
Option | Range/Options | Description | Default |
---|---|---|---|
--animation | --no-animation | Enables typewriter-like animation for output. | animation |
--code | --no-code | Toggles the generation of programming code snippets. | no-code |
--editor | --no-editor | Activates the system’s default editor for input prompts. | no-editor |
--execute | Executes shell commands provided by the --shell option. | ||
--help | Displays the help message with a list of commands and exits. | ||
--shell | Outputs shell commands instead of plain text. | ||
--spinner | --no-spinner | Shows or hides the loading spinner during API requests. | spinner |
--temperature | FLOAT RANGE [0.0<=x<=1.0] | Controls output randomness, with higher values increasing diversity. | 1.0 |
--top-probability | FLOAT RANGE [0.1<=x<=1.0] | Restricts output to the most likely tokens, enhancing relevance. | 1.0 |
Example commands:
Ask Shell-GPT to act by renaming a file from ‘old_filename.txt’ to ‘new_filename.txt’. (You can adjust the filenames in the prompt to match your actual file names) :
sgpt "Rename the file 'old_filename.txt' to 'new_filename.txt'"
Ask Shell-GPT to generate Python code for a simple web scraper that extracts data from a website:
sgpt --code "Write Python code for a web scraper that extracts data from a website" --temperature 0.7 --length 300
Ask Shell-GPT to translate short phrases or sentences between languages:
sgpt "Translate the phrase 'Hello, how are you?' into Spanish."
Adjust the prompts and parameters to suit your specific needs and preferences.
We have successfully installed and tested some of the functions of the Shell-GPT. Feel free to experiment with different Shell-GPT prompts and advanced uses of Shell-GPT to enhance your productivity, creativity, and exploration of various topics. 💻😎
Also Read:
Use Linux Command Line Easily with Shell Genie AI