The Wayback Machine - https://web.archive.org/web/20240717051738/https://www.geeksforgeeks.org/how-to-use-chatgpt-on-linux/
Open In App

How to Use chatgpt on Linux

Last Updated : 08 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

OpenAI has developed an AI-powered chatbot named `ChatGPT`, which is used by users to have their answers to questions and queries. One can access ChatGPT on searchingness easily. But some users want to access this chatbot on their Linux System. It can be accessed as a Desktop application on Ubuntu or can be accessed by the Linux terminal. 

In this article, we are going to discuss two ways to get ChatGPT on our terminal in Linux System. They are Terminalgpt and Shell-GPT (sgpt).

Install and Use Terminalgpt on our Linux System.

We can say that TermialGPT is a chatbot for our terminal which is powered by OpenAI’s GPT. It can be used to get real-time responses on a wide range of topics and questions.

We are going to install and configure terminalgpt in our Linux System. There are many Linux distributions, but in this article, we are going to use Ubuntu (22.04.2 LTS (Jammy Jellyfish)). We need to follow some simple steps to use it:

Step 1: Installing node.js in our Linux System

We need to install Node.js in our Linux system because the package we are going to install in our system requires `npx` and we know that both `npm` and `npx` are typically installed along with Node.js.

1) Download Node.js (version = 18.16.0)

wget https://nodejs.org/dist/v18.16.0/node-v18.16.0-linux-x64.tar.gz

Here we have used `wget` to download the Node.js binary package for Linux.

2) Extract the Node.js package:

tar -xvf node-v18.16.0-linux-x64.tar.gz

The tar command is used to extract the contents of the downloaded tarball.

3) Move the Node.js directory:

sudo mv node-v18.16.0-linux-x64 /usr/local/

Here, the mv command is used to move the extracted Node.js directory to the /usr/local directory. The /usr/local directory is commonly used for locally installed software.

4) Create symbolic links:

sudo ln -s /usr/local/node-v18.16.0-linux-x64/bin/node /usr/local/bin/node
sudo ln -s /usr/local/node-v18.16.0-linux-x64/bin/npm /usr/local/bin/npm

These commands create symbolic links (ln -s) that point to the Node.js executable (node) and the Node Package Manager (npm) in the /usr/local/bin directory. This step allows you to run Node.js and npm from anywhere in the system.

5) Verifying the installation:

node -vnpm -v

These commands will display the installed versions of Node.js and npm, respectively.

Step 2: Installing terminalgpt and some global packages

npx terminalgpt

This installed terminalgpt in our system.

npm install -g lowdb steno inquirer

The latest versions of the lowdb, steno, and inquirer packages are installed globally on our system.

Step 3: Creating our OpenAI API key

1) Visit the OpenAI website:

Go to the OpenAI website at https://www.openai.com/.

Sign in or create an account: If you already have an account, sign in using your credentials. Otherwise, click on the “Sign Up” button to create a new account.

On the top right corner CLICK on profile. You will see `view API keys` Clicke on it.

view API keys

view API keys

2) Create a new API key:

After selecting view API keys, Click on Create new secrete key

3) Enter your key name:

Enter your desired key name here and click on create secret key.
 

4) KEY Generated:

Copy your Key from the prompt.

201.webp

Note: Copy the Prompted key and save it somewhere. Do not share your key with anyone, for security reasons.

Step 4: Enter API Key.

npx terminalgpt chat

This will ask us to enter our API key, enter your API key that you have copied from the prompt.

We have this option (enter your API key) appears only once.

Step 5: Use of TerminalGPT

Now we can ask any question we want to the terminalgpt.

For Example:

npx terminalgpt chat

This time it will not ask to enter API again. Now we can ask any question we want.

“What is the capital of India”

Installation of SGPT in our Linux system.

SGPT is known as ShellGPT which is a powerful toll that utilizes OpenAI’s GPT (Generative pre-trained Transformer) that provides an interactive shell experience to the User. It can be used to execute commands, get code completions, give answers to the questions we ask.

In this article we are going to Install SGPT in our linux system (Ubuntu). One can follow easy steps of installation and configuration.

Step 1: Update and Upgrade the System

sudo apt update
sudo apt upgrade -y

These are used in Ubuntu and other Debian-based systems to update and upgrade the installed software packages.

Step 2: Install Python 3 and PIP

If Python 3 is not already installed, run the following command:

sudo apt install python3 -y

Install PIP (Python package manager) using this command.

sudo apt install python3-pip -y

Step 3: Install SGPT via PIP

To install SGPT, execute the following command:

pip install shell-gpt --user

Step 4: Adding ShellGPT in Our Linux path

Edit our shell configuration file (e.g., ~/.bashrc), use text editor like nano for adding this line in the end of the file:

nano ~/.bashrc
#Add this line in the endexport 
PATH=$PATH:~/.local/bin

Refresh the shell configuration or open a new terminal to get the updated terminal.

#use this command to refresh the terminal
source ~/.bashrc

Step 5: Creating an OpenAI API key.

1) Visit the OpenAI website:

Go to the OpenAI website at https://www.openai.com/.

Sign in or create an account: If you already have an account, sign in using your credentials. Otherwise, click on the “Sign Up” button to create a new account.

On the top right corner CLICK on profile. You will see `view API keys` Click on it.

view API keys

view API keys

2) Create a new API key:

After selecting view API keys, Click on Create new secrete key

3) Enter your key name:

Enter your desired key name here and click on Create secret key.

4) KEY Generated:

Copy your Key from the prompt.

201.webp

Note: Copy the Prompted key and save it somewhere. Do not share your key with anyone, for security reasons.

Step 6: Create a file named .sgptrc inside the ~/.config/shell_gpt directory

nano ~/.config/shell_gpt/.sgptrc

Add the following line to the file.

OPENAI_API_KEY=<YOUR_API_KEY>

replacing <YOUR_API_KEY> with your actual OpenAI API key

Step 7: Use of SGPT.

To test if SGPT is working correctly, open a new terminal and run the command:

sgpt --shell

Now you can ask it questions related to shell.

For Example:

sgpt --shell "echo hello"

type option(e)

sgpt --shell "ls"

type option(e)

Certainly, it has few Options.

#use this to see all the available options 
sgpt --help
Create

Conclusion

In this article we have discussed two ways for using chatgpt on our Linux terminal, both ways are opensource and very useful. First, we discussed how can we use terminalgpt on our terminal, we have discussed step-by-step installation of it. Then we discussed Shell-GPT (sgpt) and its complete installation on our system. A user can easily understand and chatgpt on their Linux System easily by going through this article step by step.



Previous Article
Next Article

Similar Reads

How to get ChatGPT Desktop Application on Ubuntu Linux
ChatGPT is an AI-powered chatbot developed by OpenAI, which can give answers to a wide range of complex and difficult questions and also can provide personalized responses to the user. The ChatGPT Desktop application is one of the convenient ways to access the ChatBot on Ubuntu Linux that allows users to interact with ChatGPT without the need for a
2 min read
10 Best ChatGPT Plugins You Should Use
ChatGPT is a Natural Language Processing tool released by OpenAI in 2023. Almost like a human, this tool can interact with the person by its ability to answer follow-up questions, admit mistakes, correct responses challenge incorrect premises, reject inappropriate requests, and much more. With these abilities, ChatGPT has become a very powerful and
9 min read
How to Use ChatGPT with Siri on iPhone
In today's tech-savvy world, we're constantly amazed by the wonders of artificial intelligence (AI). And guess what? Two incredible AI innovations, ChatGPT and Siri, have joined forces to revolutionize your iPhone experience! ChatGPT is your go-to buddy for generating human-like text and engaging conversations, while Siri is the voice assistant tha
7 min read
How to Use ChatGPT to Analyze Data?
In an age where everything is online, increased data in all formats is almost obvious. This data forms the basis of most of the marketing strategies and further product design and assembly. It is almost impossible to work without data today. Right from social media to online shopping, everything is data-driven, and this data drive the business ahea
9 min read
10 Best Ways Developers Can Use ChatGPT-4
ChatGPT has gained so much popularity these days. Developers or be they any learner, everyone is relying on ChatGPT for gathering information. It has become a daily habit of using it for various purposes - generating emails, posts, articles, or any sort of information. Technology is advancing day by day and thus the invention of ChatGPT-4 has come
6 min read
How to Use ChatGPT API in NodeJS?
ChatGPT is a very powerful chatbot by OpenAI which uses Natural Language Processing to interact like humans. It has become very popular among developers and is being widely used for some of its state-of-the-art features like understanding and interpreting code and even generating code based on textual requirements. OpenAI has not only provided its
8 min read
How to Use ChatGPT API in Python?
ChatGPT and its inevitable applications. Day by Day everything around us seems to be getting automated by several AI models using different AI and Machine learning techniques and Chatbot with Python, there are numerous uses of Chat GPT and one of its useful applications we will be discussing today. So, before moving to its application let's know a
5 min read
How to use ChatGPT for passive income?
Passive income refers to money earned on an ongoing basis with little to no effort required to maintain it. Unlike active income, which requires ongoing work or effort to earn money, passive income streams continue to generate income even when you're not actively working. Why do we need passive income? Passive income is needed because it provides a
12 min read
How to Use ChatGPT For Making PPT?
With the increasing use of Artificial Intelligence in every task we do, the launch of ChatGPT has led to an all-time high dependency on AI for content generation. ChatGPT created by OpenAI and released in November 2022, is making a Whipple in the complete content industry, from article writing, to post generation. There is hardly anything today tha
7 min read
How to Use ChatGPT For Social Media Marketing With 10 Examples
With the advent of ChatGPT and advancements in Artificial intelligence (AI), the lives of people have changed for the better. There is a marvelous boom in the tech industry and numerous other fields are also seeking the help of ChatGPT for creating better opportunities. Among them, the first one is Social Media Marketing where entrepreneurs are fin
6 min read
Article Tags :