A step-by-step tutorial on installing and utilising ChatGPT in a Linux terminal

ChatGPT's Subscription Package Can Now Be Bought in India
ChatGPT's Subscription Package Can Now Be Bought in India

ChatGPT is an AI chatbot that was established in November 2022 by OpenAI. It can execute tasks like writing and debugging code, composing narratives and simulating human conversations. It’s free to use, but there are plans to monetise the AI. You can also access it from their website. Regardless, you can use the unofficial ChatGPT wrapper, an open-source command line tool that can interact with the renowned AI ChatGPT directly from the Terminal or in your Python script.

If you are a user of Linux and want to bring the wisdom of this AI chatbot to your system, ShellGPT is the best option for you. It brings the power of ChatGPT straight to your Linux terminal. ShellGPT provides answers and thoughtful advice, writes commands and code for you, supporting you in navigating the command line efficiently.

This article will be the guideline for you on how to set up and use ChatGPT in a Linux terminal and how to Install and use the ShellGPT command line tool.

 

ChatGPT is available now as an extension for

 

  

 

A guide to installing Chat GPT for Linux terminal

  • Log in to the OpenAI web page and get your API key.
  • Change ‘your_API_key_value’, which you got from the openai webpage, before running the following command:
  • Echo “OPENAI_API_KEY=your_API_key_value” > ~/.customizer/bin/chatGPT/Content/Python/chatBot/.envBash
  • That’s it. Now type chatbot in the console, and magic happens. Use ‘exit’ or ‘quit’ to end a conversation.
  •  You can use TalkGPT (but not yet on Android) to speak to the console, and the AI will also respond using a custom voice.
  • You can also use the code GPT function to generate code when comments are passed to it.

 

Conditions for installing ChatGPT in Linux CLI

You need to fulfil some conditions before installing ShellGPT on your Linux system. These are not very complex tools and can be installed with simple commands.

 

1. Install Python

Python is an essential tool, and like many other Linux tools and libraries, Shellgpt is the command-line version of ChatGPT and is also built in Python. ChatGPT has been developed using Python along with other languages as well. Generally, Python comes pre-installed in most recent Linux distros. So first, check the installed Python version on your Linux PC with this command:

  python3 –version

 If the above command outputs any error, Python is not installed, or you have deprecated python2.7 installed on your system.

 

2. Install the pip package manager

Pip is a cross-platform package supervisor for Python. It helps control the various Python packages and libraries to bring ChatGPT to Linux. You can install and upgrade, and uninstall the required packages using a single command. It is usually pre-installed with Python on most Linux, but if it is not installed, you can install it with this command:

sudo apt-get -y install python3-pip

While installed, you can scan the installed pip version on Linux with the following command:

pip3 –version

3. Install the venv module

This module is unimportant for ShellGPT or ChatGPT; we suggest installing it to construct a separate virtual environment on Linux to bypass conflicts with other libraries. Installing any library or package will install multiple background dependencies that may interrupt other libraries. To create a virtual setting for a project, you must need the “venv” module, which can be installed using the command below:

sudo apt install python3-venv

 

 

Set up ShellGPT to use ChatGPT in a Linux Terminal.

 

We have separated the instructions for installing ShellGPT on your Linux PC into four sections for easy understanding. Let’s start by setting up the Environment to get the OpenAI API key and installing the chatbot in the Terminal.

 

1. Set up the Environment

Now that you’ve covered the dependencies let’s create an environment to access ChatGPT from your Linux terminal with the following steps:

  1. First, select Terminal or use the “Ctrl + Alt + T” (keyboard shortcut).
  2. Use the below command to create a new directory and keep all the files organised.
  3. Then, switch to the new directory you created with the “change directory” command:

        cd <new_directory_name>

  1. Use the down command to make a virtual territory with the venv module. We used the name “chatgpt_cli” for our virtual territory.
  2. The virtual environment you created will be disabled by default. To enable the Environment, utilise this prompt:

source <virtual_environment_name>/bin/activate

While you execute the above command, the shell prompt will now display the virtual environment name in parentheses, like so:

(<virtual_environment_name>)<username>@<system_name>

 

2. Get  your OpenAI API key

To use ChatGPT’s services on Linux, you will need an OpenAI API key. Currently, OpenAI is offering a $5 credit for trial usage. Once you run out of credits, you must pay for access to the API

  1. Navigate OpenAI’s website and create a new OpenAI account. Log in and proceed to the next step if you have an account.
  2. Next, click on your profile picture in the upper right corner and select “View API Keys” from the drop-down menu.
  3. Here, you will see all earlier generated API keys, if any. Click the “Generate New Secret Key” button to develop a new API key.
  4. A new pop-up box will activate with your API Key. Do not transfer this API key to anyone or share it publicly. Copy your API key to a secure file or location, as you can only see it once. You cannot copy the API key after you click “OK” here.
  5. Create an environment variable for this API key with the command below. You can create an environment variable in Linux using the “export” command.

        export OPENAI_API_KEY=<your_OpenAI_API_key_here>

  1. Check the Environment variables by listing them with the env command:

        Env

  1. This variable is stored temporarily for the current session only.
  2. Save the file and exit from the text editor after adding the OpenAI API key. Now, run this command to make the changes take place :

        source .bashrc

  1. Finally, confirm the changes with the env command:

         Env

3. To use ChatGPT, install ShellGPT

After setting up the Environment, you can install ChatGPT on Linux.

 

4.ShellGPT: Syntax and Options

Now you have installed ShellGPT; you must be interested in using it for various tasks. But before that, let’s examine the syntax and some options that we can use to make our outputs attractive.

         Sgpt <options> <input_query>

 

Distroid

Final thought 

ShellGPT brings the power of ChatGPT straight to your Linux terminal. It makes working with the command line easier for new and experienced users and adds additional features. But always keep in mind not to share any sensitive information or data, especially your company’s proprietary code, with any AI model.

 

Previous articleWatch IPl 2023 Free & Fast Before TV & Crickbuzz
Next articleGoogle Play Music To Shut Down In September 2020, To Be Replaced By YouTube Music
Rock
Hi, I'm Rock, the creator of TechIHD. I simplify tech news, tutorials, and reviews to make technology easy and accessible for everyone, whether you're new or a tech enthusiast.

LEAVE A REPLY

Please enter your comment!
Please enter your name here