How to use ChatGPT from Ubuntu Terminal using ShellGPT

People use this universal, versatile tool to tell jokes, write code, and even answer the most random questions. It's easy to use ChatGPT on other operating systems, so as a Linux user, are you willing to be left behind?

You can also enjoy a version of ChatGPT for Linux, ShellGPT. Here's how to install and use this AI tool from Ubuntu Terminal with a few simple steps.

Step 1: Install Python and PIP on the machine

Like most AI-powered tools, even ShellGPT runs on Python. Although Python is usually installed by default on most Linux distributions, you can check its installation through the version information. If Python is not available on your machine, you must install it before moving on to the next steps.

Open a Terminal and enter the following commands to check the version of Python:

python3 --version

If the command returns the version number output, you can rest assured that everything will be ready to go. However, if you encounter any errors, you should install Python on Ubuntu, before installing PIP.

Now that you have Python installed on your machine, it's time to install PIP, Python's native package manager.

Although PIP is usually pre-installed with the Python package, it is best to check the version first for its installation status. Run the following command to check if it is installed on your machine:

 

pip --version

If you get an error after executing, you need to install the package manager:

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

You can use the following command to install it:

sudo apt install python3-pip

How to use ChatGPT from Ubuntu Terminal using ShellGPT Picture 1

After installation, you can use the --version command again to check if the installation was successful.

Step 2: Install and set up a virtual environment using Python

Now that Python and PIP are ready, you can set up Python's virtual environment to make it convenient to install and run ShellGPT. Virtual environments are ideal for running isolated programs as they can avoid library conflicts.

With the included virtual environment, you can limit the interaction between the system's programs and the virtual environment while performing various executables in the silo.

Note : Using virtual environment is an optional step, to avoid any unforeseen risks while installing and using Python libraries.

 

To create a virtual environment using Python, you need to install the venv module:

sudo apt install python3-venv -y

How to use ChatGPT from Ubuntu Terminal using ShellGPT Picture 2

Set up virtual environment

After installing the virtual environment, you can set up the virtual environment so that it can seamlessly support ShellGPT commands.

First, create a new folder to organize and store files. You can use the mkdir command, followed by the directory name, like this:

mkdir cli-shellgpt

Navigate to this newly created directory with the cd command:

cd cli-shellgpt

Then, create a new virtual environment with the venv command, followed by the environment name:

python3 -m venv cli-shellgpt

Since the virtual environment is not enabled by default, you must enable it manually with the activate script :

source cli-shellgpt/bin/activate

As soon as you execute the above command, you will notice the default Linux shell prompt of Linux changes, as shown below:

(cli-shellgpt) sahil@vm:

How to use ChatGPT from Ubuntu Terminal using ShellGPT Picture 3

 

Step 3: Generate OpenAPI key

Since the virtual environment is ready, you must connect your OpenAI services and Ubuntu machine to run ShellGPT. For this to work, you must navigate to the OpenAI website and create an account there.

If you already have an account, you can log in with your credentials and navigate to your profile picture, located at the top right of the website.

Click View API Keys , then click Create new secret key .

How to use ChatGPT from Ubuntu Terminal using ShellGPT Picture 4

Do not share this key with anyone because the connection is private and only used on your machine.

Copy the API key from the dialog and save it somewhere because you won't be able to see the same key again.

How to use ChatGPT from Ubuntu Terminal using ShellGPT Picture 5

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

export OPENAI_API_KEY= 

Add and verify the API key to the virtual environment variable

When you execute the API key this way, Linux will only use it for a single instance. However, if you want the executable to be permanent, save it to the .bashrc file.

All you have to do is enter the first command and enter the next in a text editor:

 

nano ./bashrc export OPENAI_API_KEY= 

How to use ChatGPT from Ubuntu Terminal using ShellGPT Picture 6

Save and exit the editor. Then use the source command to trigger the changes.

source ./bashrc

Finally, verify the API key with the env command.

env

How to use ChatGPT from Ubuntu Terminal using ShellGPT Picture 7

Your OPENAI_API_KEY environment variable should be listed in the output.

Step 5: Install ShellGPT on Ubuntu

Once all the installation procedures are complete, you can simply move on to the best part, installing ShellGPT. The installation steps are quite simple and you can install the tool with the following command:

pip3 install shell-gpt

How to use ChatGPT from Ubuntu Terminal using ShellGPT Picture 8

Let the installation finish; meanwhile, you can see some cool ways to use AI tools through your Terminal window.

Use ShellGPT to run queries via Terminal

The whole purpose of installing ShellGPT is to make your life easier. To use Terminal as a search engine and run some queries, you can use the sgpt command, followed by your query in quotes:

 

sgpt "How many galaxies exist within the universe"

How to use ChatGPT from Ubuntu Terminal using ShellGPT Picture 9

Use ShellGPT to generate code

You can also use ShellGPT to generate code. You can do that by passing the correct command with the sgpt command :

sgpt --code "print the Fibonacci series"

How to use ChatGPT from Ubuntu Terminal using ShellGPT Picture 10

The output includes code that you can execute in Python to generate the Fibonacci sequence.

4 ★ | 1 Vote

May be interested

  • How to check available memory in UbuntuHow to check available memory in Ubuntu
    linux, bsd and * nix operating systems in general, provide users with many options to view information within the system. just open a terminal and type cat / proc / cpuinfo, cat / proc / meminfo or cat / proc / net / wireless.
  • 6 interesting terminal commands on Mac6 interesting terminal commands on Mac
    terminal is a handy utility, often found on unix-based computers, such as linux and macos. there are many interesting things to do in the terminal. regardless of your experience, you can use these great terminal commands on mac.
  • 10 Essential Chrome Extensions to Use ChatGPT10 Essential Chrome Extensions to Use ChatGPT
    when using chatgpt regularly, especially if you're on the free version, some chrome extensions can significantly improve your experience.
  • How to Install Themes in UbuntuHow to Install Themes in Ubuntu
    this wikihow teaches you how to install themes on ubuntu 18.04 lts. many themes from ubuntu's software repositories can be installed in a terminal window. some themes must be manually extracted using archive manager. to apply installed...
  • How to register for ChatGPT's new plugin featureHow to register for ChatGPT's new plugin feature
    chatgpt plugins are software components integrated into the chatgpt platform. they provide chatgpt with additional information and allow chatgpt to perform specific actions on the user's behalf.
  • How to spell check in Linux TerminalHow to spell check in Linux Terminal
    linux also has a command line spell checker utility in terminal. the utility is called aspell and is installed by default on ubuntu. this is how you can use aspell to check spelling in a terminal.
  • How to use Terminal on a MacHow to use Terminal on a Mac
    terminal on mac is a command line interface that allows you to use unix commands to complete some tasks much faster than using a graphical user interface (gui). with the terminal command, you can open files, improve your mac's performance, and more. here's how to use terminal on mac, including some basic commands you can get started.
  • How to Format USB on UbuntuHow to Format USB on Ubuntu
    with ubuntu linux, you can use several utilities to format usb, such as the disk utility feature that comes with ubuntu or terminal. regardless of which feature you use, formatting the usb will only take you a few minutes.
  • 8 best free Terminal Emulator apps for Android8 best free Terminal Emulator apps for Android
    terminal emulator applications on android are handy when you want to execute commands within the android operating system just like on linux.
  • What is ChatGPT Plus? How to register ChatGPT Plus in VietnamWhat is ChatGPT Plus? How to register ChatGPT Plus in Vietnam
    according to new information, chat gpt plus has now been deployed in the vietnamese market so that we can buy and register our accounts, without expecting vpn software or using another phone number to register to use chat gpt like now.