{"id":2706,"date":"2024-02-22T20:33:37","date_gmt":"2024-02-22T15:03:37","guid":{"rendered":"https:\/\/www.veeble.org\/kb\/?p=2706"},"modified":"2025-02-20T15:58:36","modified_gmt":"2025-02-20T10:28:36","slug":"how-to-use-chatgpt-on-linux-terminal","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/how-to-use-chatgpt-on-linux-terminal\/","title":{"rendered":"How to use ChatGPT on Linux Terminal"},"content":{"rendered":"\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/02\/Installing-ChatGPT-on-Linux-Terminal.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"504\" data-id=\"2804\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/02\/Installing-ChatGPT-on-Linux-Terminal.png\" alt=\"How to use ChatGPT on Linux Terminal\" class=\"wp-image-2804\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/Installing-ChatGPT-on-Linux-Terminal.png 1200w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/Installing-ChatGPT-on-Linux-Terminal-300x126.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/Installing-ChatGPT-on-Linux-Terminal-1024x430.png 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/Installing-ChatGPT-on-Linux-Terminal-768x323.png 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>Have you ever found yourself delving deep into the world of Linux, longing for the wit and wisdom of an AI chatbot right there in your trusted terminal? Well, fear not, because ShellGPT is here to accompany you on this digital journey. By seamlessly integrating the capabilities of ChatGPT into your Linux Terminal, ShellGPT transforms into your virtual assistant, ready to provide insightful answers and clever suggestions, and even generate commands and code for you. Whether you&#8217;re a developer, writer, or researcher, Shell-GPT offers a seamless experience for crafting text-based content. <br>In this guide, we&#8217;ll walk you through the various steps of the installation process step by step.<\/p>\n\n\n\n<p><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"installation\">Installation<\/h4>\n\n\n<p>Before proceeding with the installation, ensure that the system is up to date and that the packages: python3, pip3, and python3-venv are installed on your system. If not, you can install them using the following commands:<\/p>\n\n\n\n<p>For Ubuntu\/Debian:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update -y\nsudo apt install python3 python3-pip python3-venv -y<\/code><\/pre>\n\n\n\n<p>For Centos\/RedHat-based OS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum update -y\nsudo yum install python3 python3-pip python3-venv -y<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"virtual-environment-for-shell-gpt\">Virtual Environment for Shell GPT:<\/h4>\n\n\n<p>Creating a virtual environment isn&#8217;t strictly necessary but is highly recommended, especially for Python projects. It helps manage dependencies, versions, and packages in an isolated setting without affecting global Python settings on the Linux server. This practice ensures that your project has all its requirements contained, making it easier to manage and replicate across different machines or setups. For applications like ShellGPT, using a virtual environment can prevent conflicts between the tool&#8217;s dependencies and those of other Python projects on the same system.<\/p>\n\n\n\n<p>To create and activate a virtual environment for this project, execute the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir sgpt &amp;&amp; cd sgpt &amp;&amp; python3 -m venv sgpt &amp;&amp; source sgpt\/bin\/activate<\/code><\/pre>\n\n\n\n<p>Now, your prompt will be changed to the newly created virtual environment.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-22-163205.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"815\" height=\"67\" data-id=\"2767\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-22-163205.png\" alt=\"\" class=\"wp-image-2767\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-22-163205.png 815w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-22-163205-300x25.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-22-163205-768x63.png 768w\" sizes=\"auto, (max-width: 815px) 100vw, 815px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"acquiring-an-openai-api-key\">Acquiring an OpenAI API Key:<\/h4>\n\n\n<p>An API key is required for setting up Shell GPT on your Linux, and this can be set up by configuring your OpenAI\/ChatGPT account&#8217;s API to the ShellGPT. <\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/02\/api-1.gif\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1910\" height=\"864\" data-id=\"2774\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/02\/api-1.gif\" alt=\"Generating an OpenAI API Key\" class=\"wp-image-2774\"\/><\/a><\/figure>\n<\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Steps to create an API key:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>To create an API key from OpenAI and utilize it on your ShellGPT, start by heading to the OpenAI website: <a href=\"https:\/\/platform.openai.com\/docs\/overview\" target=\"_blank\" rel=\"noopener\">https:\/\/platform.openai.com\/docs\/overview<\/a> on your browser and signing up or logging in.<\/li>\n\n\n\n<li>Once logged in, move the cursor to the left side tab, and look for the API key section in the resulting menu.  Click on API Keys and then click &#8220;Create secret key&#8221; in the next window.<\/li>\n\n\n\n<li>Give a name for the key and generate a new API key. When you create a new key, be sure to securely copy and save it immediately, as it will only be displayed once for security reasons.<\/li>\n<\/ol>\n\n\n\n<p><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"setting-api-and-environment-variables-in-linux\">Setting API and Environment Variables in Linux:<\/h4>\n\n\n<p>After successful API key extraction from OpenAI add it as an environment variable in the <code>.bashrc<\/code> file, this is by executing the following command. (Remember to replace &#8220;<span style=\"background-color: initial;color: var(--ast-global-color-3)\"><em><code>your api key<\/code><\/em><\/span>&#8221; in the command with your actual OpenAI API key before running the command.):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo 'export OPENAI_API_KEY=<span style=\"background-color: initial;color: var(--ast-global-color-3)\"><em><strong>your api key<\/strong><\/em><\/span>' &gt;&gt; ~\/.bashrc<\/code><\/pre>\n\n\n\n<p>Execute the command <code>source ~\/.bashrc<\/code> to run the new environment variable we set in <code>.bashrc file<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>source ~\/.bashrc<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-verse\">To enter again into virtual environment use the command: <code>source sgpt\/bin\/activate<\/code><\/pre>\n\n\n<h4 class=\"wp-block-heading\" id=\"installing-shellgpt-final-step\">Installing Shell-GPT (Final Step)<\/h4>\n\n\n<p>The prerequisites for getting ready for installing Shell-GPT will be ready by now. Now go ahead with installing Shell-GPT:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip3 install shell-gpt<\/code><\/pre>\n\n\n\n<p>After installation, verify whether Shell-GPT is installed or not via executing the below command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sgpt --version<\/code><\/pre>\n\n\n\n<p>If successful, this command should display the installed version of Shell-GPT like this:<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-4 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-22-192650.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"433\" height=\"64\" data-id=\"2782\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-22-192650.png\" alt=\"sgpt --version\" class=\"wp-image-2782\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-22-192650.png 433w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/Screenshot-2024-02-22-192650-300x44.png 300w\" sizes=\"auto, (max-width: 433px) 100vw, 433px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"running-shellgpt\"><strong>Running Shell-GPT<\/strong><\/h4>\n\n\n<p>Shell-GPT commands offer versatility and control over text generation directly from your terminal. Whether you&#8217;re crafting stories, poems, or summaries, the prompts you enter allow you to tailor the output to your needs. Utilize the <code>shell-gpt<\/code> command followed by the prompt you wish to generate text for.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sgpt \"Your Prompt Here\"<\/code><\/pre>\n\n\n\n<p><strong>Parameters that can be used with sgpt commands:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Option<\/th><th>Range\/Options<\/th><th>Description<\/th><th>Default<\/th><\/tr><\/thead><tbody><tr><td><code>--animation<\/code><\/td><td><code>--no-animation<\/code><\/td><td>Enables typewriter-like animation for output.<\/td><td>animation<\/td><\/tr><tr><td><code>--code<\/code><\/td><td><code>--no-code<\/code><\/td><td>Toggles the generation of programming code snippets.<\/td><td>no-code<\/td><\/tr><tr><td><code>--editor<\/code><\/td><td><code>--no-editor<\/code><\/td><td>Activates the system&#8217;s default editor for input prompts.<\/td><td>no-editor<\/td><\/tr><tr><td><code>--execute<\/code><\/td><td><\/td><td>Executes shell commands provided by the <code>--shell<\/code> option.<\/td><td><\/td><\/tr><tr><td><code>--help<\/code><\/td><td><\/td><td>Displays the help message with a list of commands and exits.<\/td><td><\/td><\/tr><tr><td><code>--shell<\/code><\/td><td><\/td><td>Outputs shell commands instead of plain text.<\/td><td><\/td><\/tr><tr><td><code>--spinner<\/code><\/td><td><code>--no-spinner<\/code><\/td><td>Shows or hides the loading spinner during API requests.<\/td><td>spinner<\/td><\/tr><tr><td><code>--temperature<\/code><\/td><td>FLOAT RANGE [0.0&lt;=x&lt;=1.0]<\/td><td>Controls output randomness, with higher values increasing diversity.<\/td><td>1.0<\/td><\/tr><tr><td><code>--top-probability<\/code><\/td><td>FLOAT RANGE [0.1&lt;=x&lt;=1.0]<\/td><td>Restricts output to the most likely tokens, enhancing relevance.<\/td><td>1.0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Example commands:<\/strong><\/p>\n\n\n\n<p>Ask Shell-GPT to act by renaming a file from &#8216;old_filename.txt&#8217; to &#8216;new_filename.txt&#8217;. (You can adjust the filenames in the prompt to match your actual file names) :<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-d8862b790f73aeff6390ae2c883635ba\"><code>sgpt \"Rename the file 'old_filename.txt' to 'new_filename.txt'\"<\/code><\/pre>\n\n\n\n<p>Ask Shell-GPT to generate Python code for a simple web scraper that extracts data from a website:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-9f267155eca60419b1ee6dff37e29d86\"><code>sgpt --code \"Write Python code for a web scraper that extracts data from a website\" --temperature 0.7 --length 300<\/code><\/pre>\n\n\n\n<p>Ask Shell-GPT to translate short phrases or sentences between languages:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-41b7c4990bc3810b60d5e4e33aa0dca5\"><code>sgpt \"Translate the phrase 'Hello, how are you?' into Spanish.\"<\/code><\/pre>\n\n\n\n<p>Adjust the prompts and parameters to suit your specific needs and preferences.<\/p>\n\n\n\n<p>We have successfully installed and tested some of the functions of the Shell-GPT. Feel free to experiment with different Shell-GPT prompts and advanced uses of Shell-GPT to enhance your productivity, creativity, and exploration of various topics.  \ud83d\udcbb\ud83d\ude0e<\/p>\n\n\n\n<div style=\"height:35px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-ebdb5147 wp-block-button\"><div class=\"uagb-cta__wrap\"><h3 class=\"uagb-cta__title\">Get started with your own VPS today!<\/h3><p class=\"uagb-cta__desc\">Our VPS hosting plans are perfect for businesses and individuals who need a powerful and reliable server to host their website or application.<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/www.veeble.com\/in\/kvm-vps\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_blank\" rel=\"noopener noreferrer\">Get started<svg xmlns=\"https:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\"><path d=\"M504.3 273.6l-112.1 104c-6.992 6.484-17.18 8.218-25.94 4.406c-8.758-3.812-14.42-12.45-14.42-21.1L351.9 288H32C14.33 288 .0002 273.7 .0002 255.1S14.33 224 32 224h319.9l0-72c0-9.547 5.66-18.19 14.42-22c8.754-3.809 18.95-2.075 25.94 4.41l112.1 104C514.6 247.9 514.6 264.1 504.3 273.6z\"><\/path><\/svg><\/a><\/div><\/div>\n\n\n\n<div style=\"height:35px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Also Read:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-veeble-hosting wp-block-embed-veeble-hosting\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/www.veeble.org\/kb\/shell-genie-ai-linux-command-line\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever found yourself delving deep into the world of Linux, longing for the wit and wisdom of an AI chatbot right there [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":2777,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[5],"tags":[],"class_list":["post-2706","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/featured-image-1.png",1080,566,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/featured-image-1-150x150.png",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/featured-image-1-300x157.png",300,157,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/featured-image-1-768x402.png",768,402,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/featured-image-1-1024x537.png",1024,537,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/featured-image-1.png",1080,566,false],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/02\/featured-image-1.png",1080,566,false]},"uagb_author_info":{"display_name":"Adrian Antony","author_link":"https:\/\/www.veeble.com\/kb\/author\/adrian\/"},"uagb_comment_info":0,"uagb_excerpt":"Have you ever found yourself delving deep into the world of Linux, longing for the wit and wisdom of an AI chatbot right there [&hellip;]","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/2706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=2706"}],"version-history":[{"count":27,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/2706\/revisions"}],"predecessor-version":[{"id":7361,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/2706\/revisions\/7361"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/2777"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=2706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=2706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=2706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}