DEV Community

Anand Vikkath
Anand Vikkath

Posted on

Install ShellGPT with Gemini API

1. Install System Dependencies

Ensure your Ubuntu system is ready with Python and the required virtual environment tools.

sudo apt update
Enter fullscreen mode Exit fullscreen mode
sudo apt install python3 python3-pip python3-venv -y
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

3. Install ShellGPT with LiteLLM

ShellGPT needs the litellm extra to talk to Google's API.

pip install "shell-gpt[litellm]"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

The Permanent VENV activation

Open your .bashrc file:

nano ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Scroll to the bottom and add this line:

alias sgpt='~/shellgpt/venv/bin/sgpt'
Enter fullscreen mode Exit fullscreen mode

Save and exit (Ctrl+O, Enter, Ctrl+X).

Apply the changes:

source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

[!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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)