Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form
Home » Linux » Set Up and Use ChatGPT in Linux Terminal
  • self signed sslcert
    Generate self-signed certificate and export in PFX format via PowerShell [Part 2] Windows
  • win 10 login screen
    How to Transfer User Profile to another User in Windows Windows
  • How to Change Active Directory Group Scope
    How to change Active Directory Group Scope Windows Server
  • microsoft confirms some pcs freeze after windows 10 2
    Information on BOOTP Vendor Extensions and DHCP Options Windows Server
  • hero windowsserver hyperv
    Why does the legacy PXE not does work on Generation 2 VM Virtualization
  • image 30
    How to Fix “Insufficient System Resources Exist to Complete the Requested Service” error Windows
  • jmeterlogo 3
    Install and conduct performance testing using Apache JMeter on your Web App Configuration Management Tool
  • How to Fix Microsoft Edge Not Responding on Windows 11
    How to Fix Microsoft Edge Not Responding on Windows 11 Network | Monitoring

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

  • portainer feature
    How to Install Docker Portainer on Linux Containers
  • physical
    Linux Machine: Is it Virtual or a Physical server Linux
  • sshfs
    Mounting remote directory using sshfs Linux
  • Screenshot 2022 03 15 at 10.05.53
    VMware Workstation states: What are the differences between Suspend, Power Off, and Run in Background Linux
  • 2FA For SSH in Linux
    Set Two-Factor Authentication for SSH in Linux Linux
  • Generate SSH Keys
    Associate SSH Public key with Azure Linux VM AWS/Azure/OpenShift

More Related Articles

portainer feature How to Install Docker Portainer on Linux Containers
physical Linux Machine: Is it Virtual or a Physical server Linux
sshfs Mounting remote directory using sshfs Linux
Screenshot 2022 03 15 at 10.05.53 VMware Workstation states: What are the differences between Suspend, Power Off, and Run in Background Linux
2FA For SSH in Linux Set Two-Factor Authentication for SSH in Linux Linux
Generate SSH Keys Associate SSH Public key with Azure Linux VM AWS/Azure/OpenShift

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

  • self signed sslcert
    Generate self-signed certificate and export in PFX format via PowerShell [Part 2] Windows
  • win 10 login screen
    How to Transfer User Profile to another User in Windows Windows
  • How to Change Active Directory Group Scope
    How to change Active Directory Group Scope Windows Server
  • microsoft confirms some pcs freeze after windows 10 2
    Information on BOOTP Vendor Extensions and DHCP Options Windows Server
  • hero windowsserver hyperv
    Why does the legacy PXE not does work on Generation 2 VM Virtualization
  • image 30
    How to Fix “Insufficient System Resources Exist to Complete the Requested Service” error Windows
  • jmeterlogo 3
    Install and conduct performance testing using Apache JMeter on your Web App Configuration Management Tool
  • How to Fix Microsoft Edge Not Responding on Windows 11
    How to Fix Microsoft Edge Not Responding on Windows 11 Network | Monitoring

Subscribe to Blog via Email

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

Join 1,836 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

Active Directory AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.