Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Contact
  • Reviews
  • Toggle search form
Home » Linux » Set Up and Use ChatGPT in Linux Terminal
  • Featured image dataTransfer.
    How to transfer data from an old PC to a new PC Windows
  • veeam backup for aws Processing postgres rds failed
    Veeam backup for aws Processing postgres rds failed: No valid combination of the network settings was found for the worker configuration AWS/Azure/OpenShift
  • doc register profile 1
    How to Remove a profile on outlook Network | Monitoring
  • Trellix Upgrade
    Trellix ePO On-prem 5.10.0 Service pack 1 Update 3 upgrade Security | Vulnerability Scans and Assessment
  • Screenshot 2021 02 05 at 19.09.17
    How to install and update PowerShell version 7 on Windows and Linux Windows Server
  • Turn On Or Off Auto Unlock For BitLocker Drive
    How To Turn On Or Off Auto-Unlock For BitLocker Drive In Windows 10/11 Security | Vulnerability Scans and Assessment
  • MV command in Linux
    Rename or Move Files or Directories in Linux with Bash Terminal Linux
  • FailedRegistration
    DNS Bad key 9017: The Cluster Name registration failed of one or more associated DNS names Virtualization

Set Up and Use ChatGPT in Linux Terminal

Posted on 26/04/202302/10/2024 Imoh Etuk By Imoh Etuk No Comments on Set Up and Use ChatGPT in Linux Terminal
ChatGPT-on-Linux

This post will demonstrate the set up and use ChatGPT in Linux Terminal. ShellGPT gives you the same ChatGPT AI bot in the Linux command line. We are in the era of Artificial Intelligence (AI) and we have seen how it has revolutionized the way we work. The advent of ChatGPT by OpenAI further enhances how we work, interact, and get work done quickly. Please see How to work with Azure Cognitive Service, How to find disabled Active Directory User accounts, and the Benefits of Azure API Management and how to create an API instance, How to setup PowerShell on a Linux server.

In the realm of technology, AI has become the newest buzzword. Online, ChatGPT and its variants are thriving, assisting users in carrying out routine chores with ease.

In the past, we have written guidelines on how to get started with creating your own ChatGPT-like chatbot, utilizing Bing AI in any browser, and more. See how to Use Wiki from Linux Terminal.

What if you run Linux and wish to install an AI chatbot on your system? Well, ShellGPT comes into play in this situation. It directly integrates ChatGPT’s power into your Linux Terminal. ShellGPT assists you efficiently. It helps you navigate the command line by providing solutions, insightful suggestions, and writing commands and code.

Setting Up ChatGPT in Linux Terminal

You can also learn how to associate SSH Public key with Azure Linux VM. The security of your system is paramount, see how to set Two-Factor Authentication for SSH in Linux

Step 1: Install Python

To install Python, open a terminal and type in the following commands to check Python’s version:

python3 & pip --version
Python3-version
Checking Python3 Version

If the above command returns the numeric version output of Python3 and PIP available on the system, you’re good to go. The system will display the error below if you do not have PIP installed.

Command 'pip' not found, but can be installed with:

You can run the below command to install Python3 and PIP depending on the Linux Distributions you’re using:

$sudo apt install python3
$sudo apt install python3-pip
$sudo yum –y install python3
$sudo yum –y install python3-pip

Step 2: Install Venv Module

Venv module is necessary to help create an isolated virtual environment to prevent conflict with other libraries. To install Venv, run:

sudo apt install python3-venv -y
installing-venv-module
Installing Venu Module

To set up ChatGPT on your Linux Terminal, follow the below steps: Please see GNS3 Setup: Error opening file for writing, click on Abort to stop installation, Retry to try again, or Ignore to skip this file and how to modify a Linux EBS Volume from the Console, and How to install Docker Engine on Ubuntu.

Step 3: Set Up the Virtual Environment

After installing the virtual environment, you can configure it to support ShellGPT commands easily.

Create a new directory and use the change directory command to navigate to the new directory as shown below:

sudo mkdir shellgpt-cli && cd shellgpt-cli
create-new-directory
Creating New Directory

The next thing is to create a new virtual environment with the venv command, followed by an environment name as shown below:

python3 -m venv cli-shellgpt

The virtual environment is not enabled by default, so you must manually enable it with the below command:

source cli-shellgpt/bin/activate
create-and-enable-virtual-env
Creating and Enabling a Virtual Environment

Step 4: Generate an OpenAPI Key

Now that the virtual environment is ready, to run ShellGPT, you must connect your Ubuntu machine to the OpenAI services. For this purpose, you must visit OpenAI’s website to create an account. You can simply log in if you have an account already.

After you have successfully created an account or logged in, click on  API Keys, followed by Create new secret key.

generate-openai-api-keys
Generating Open AI API Key

Note: This key should not be shared with anyone because the connection is private and should only be utilized on your machine.

generating-Open-AI-key
new-api-key

After generating the API key, copy it to a text editor somewhere as you will need it later.

To create a connection on your Ubuntu machine, create an environment variable with the export command as shown below:

export OPENAI_API_KEY=<paste your key details here>

Adding and Verifying the API Key in a Virtual Environment Variable

When you execute the API key in this manner, Linux will only utilize it once. However, you can save it in the .bashrc file, if you want to make the process permanent. To do this, run:

$sudo nano .bashrc
export OPENAI_API_KEY=<past key details here>
create-bashrc-file
Creating a .bashrc file

When you are done, save and exit the editor and use the source command to enable the changes.

. ~/.bashrc

Alternatively, you can run:

source ./bashrc
applying-changes-using-bashrc-file
Applying Changes

To verify the environment, run:

env
verifying-env
Verifying Environment

Your OPENAI_API_KEY environment variable should be displayed in the output as shown above.

Step 5: Installing ShellGPT

To utilize the function, you must install ShellGPT by running the below command:

$sudo pip3 install shell-gpt
installing-shellgpt
Installing ShellGPT
Step 6: Useing ShellGPT for Queries

To run queries using SheelGPT directly on your Linux Terminal, run:

sgpt "<your-query>"
running-queries-with-shellgpt
Running Queries

You can run as many queries as you want.

You can also ShellGPT to generate codes as shown below:

run-queries-to-generate-codes
Running Queries to Generate Codes

In this post, you have learned everything you need to get started with setting up ShellGPT which is s based on the same concept as ChatGPT on your Linux machine.

5/5 - (1 vote)

Thank you for reading this post. Kindly share it with others.

  • Click to share on X (Opens in new window) X
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on Bluesky (Opens in new window) Bluesky
  • Click to share on Threads (Opens in new window) Threads
  • Click to share on Nextdoor (Opens in new window) Nextdoor
Linux Tags:Edge

Post navigation

Previous Post: Install and configure TeamPass Password Manager
Next Post: How to create Virtual Hosts in a WAMPserver

Related Posts

  • Security enhanced linux
    How to setup SELinux on a Linux server Linux
  • Featured image WSL2 installation
    How to install WSL2 on Windows Server Linux
  • Locate Find and Grep Required 1
    Locate, Find and Grep: Search for files and patterns in Linux or Unix-like OS Linux
  • Feature image nagios
    How to Install and Configure Nagios on Ubuntu Linux
  • discorddd
    Discord Installation Guide for Linux System Linux
  • Locate Find and Grep Required 1
    A Brief Introduction to Linux and How to Create Disk Partition in Ubuntu Linux Linux

More Related Articles

Security enhanced linux How to setup SELinux on a Linux server Linux
Featured image WSL2 installation How to install WSL2 on Windows Server Linux
Locate Find and Grep Required 1 Locate, Find and Grep: Search for files and patterns in Linux or Unix-like OS Linux
Feature image nagios How to Install and Configure Nagios on Ubuntu Linux
discorddd Discord Installation Guide for Linux System Linux
Locate Find and Grep Required 1 A Brief Introduction to Linux and How to Create Disk Partition in Ubuntu Linux Linux

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

sysadmin top30a
 
  • Featured image dataTransfer.
    How to transfer data from an old PC to a new PC Windows
  • veeam backup for aws Processing postgres rds failed
    Veeam backup for aws Processing postgres rds failed: No valid combination of the network settings was found for the worker configuration AWS/Azure/OpenShift
  • doc register profile 1
    How to Remove a profile on outlook Network | Monitoring
  • Trellix Upgrade
    Trellix ePO On-prem 5.10.0 Service pack 1 Update 3 upgrade Security | Vulnerability Scans and Assessment
  • Screenshot 2021 02 05 at 19.09.17
    How to install and update PowerShell version 7 on Windows and Linux Windows Server
  • Turn On Or Off Auto Unlock For BitLocker Drive
    How To Turn On Or Off Auto-Unlock For BitLocker Drive In Windows 10/11 Security | Vulnerability Scans and Assessment
  • MV command in Linux
    Rename or Move Files or Directories in Linux with Bash Terminal Linux
  • FailedRegistration
    DNS Bad key 9017: The Cluster Name registration failed of one or more associated DNS names Virtualization

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,841 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.