1. Install System Dependencies
Ensure your Ubuntu system is ready with Python and the required virtual environment tools.
sudo apt update
sudo apt install python3 python3-pip python3-venv -y
2. Set Up a Virtual Environment
Installing in a virtual environment prevents ShellGPT from interfering with other system tools.
# Create and enter the directory
mkdir ~/shellgpt && cd ~/shellgpt
# Create the environment
python3 -m venv venv
# Activate it (you must do this every time you work in this folder)
source venv/bin/activate
3. Install ShellGPT with LiteLLM
ShellGPT needs the litellm extra to talk to Google's API.
pip install "shell-gpt[litellm]"
4. Configure Your API Keys
ShellGPT has a quirk: it was built for OpenAI, so it crashes if it doesn't find an OpenAI key, even if you are using Gemini. We bypass this by giving it a "placeholder" key.
Set the environment variables
Add these to your .bashrc so they load automatically when you log in:
echo 'export GEMINI_API_KEY="your_actual_ai_api_key_here"' >> ~/.bashrc
echo 'export OPENAI_API_KEY="placeholder"' >> ~/.bashrc
source ~/.bashrc
The Permanent VENV activation
Open your .bashrc file:
nano ~/.bashrc
Scroll to the bottom and add this line:
alias sgpt='~/shellgpt/venv/bin/sgpt'
Save and exit (Ctrl+O, Enter, Ctrl+X).
Apply the changes:
source ~/.bashrc
Now, the sgpt command will work instantly every time you log in, without needing to run the source command.
5. Configure ShellGPT (.sgptrc)
Run a quick command to ensure the configuration folder is created:
sgpt "init"
[!NOTE]
Output for this command will have API error. Ignore it
Now, open the configuration file to tell ShellGPT to use Gemini:
nano ~/.config/shell_gpt/.sgptrc
Update the following lines (or add them if they are missing):
# Use LiteLLM to bridge to Google
USE_LITELLM=true
# Set your preferred Gemini model
DEFAULT_MODEL=gemini/gemini-2.5-flash
# This MUST be here to satisfy the internal code check
OPENAI_API_KEY=placeholder
6. How to Use Your New Tool
Now that everything is linked, here is how you can use it in your day-to-day sysadmin tasks:
| Command | Usage |
|---|---|
sgpt "Hello" |
General chat/question. |
sgpt --code "python script to ping servers" |
Generates only code (no conversational text). |
sgpt --shell "list all docker containers" |
Generates a command and asks if you want to run it. |
Top comments (0)