How to Run a Program from the Command Line on Linux

This article was co-authored by Kevin Burnett and by wikiHow staff writer, Travis Boylls. Kevin Burnett is a Software Developer with over 20 years of professional experience. He works for SpiffWorkflow, a Python Process Automation tool for organizations. Prior to SpiffWorkflow, he spent the majority of his career at Rosetta Stone, a language-learning software company. He has experience with both front and back-end development and works primarily in Python, Ruby, and JavaScript. He attended the first RailsConf and the most recent PyCon US. He received an MBA and a BA in Computer Science and Spanish from Eastern Mennonite University.

This article has been fact-checked, ensuring the accuracy of any cited facts and confirming the authority of its sources.

This article has been viewed 477,733 times.

Most Linux distributions have a graphical user interface that allows you to open programs by just clicking on the program's icon in the Apps menu. However, there are situations where you may want to run a program from the Terminal. The Terminal is a powerful tool that allows you to run programs and manage your Linux system using keyboard commands. This wikiHow teaches you how to run a program from the Terminal in Linux.

Method 1 of 4:

Running a Program From the Terminal

Step 1 Press Ctrl+Alt+T to.

Fair Use (screenshot)
\n">

Press Ctrl + Alt + T to open the Terminal. You can open the Terminal using the keyboard shortcut on most Linux distributions. The keyboard shortcut is Ctrl + Alt + T. You can also click the Terminal icon in your Apps menu. It generally has an icon that resembles a black screen with a white text cursor. [1] X Research source

Step 2 Type the name of the program and press ↵ Enter.

Fair Use (screenshot)
\n"> Advertisement Method 2 of 4:

Running a Program Outside the $PATH Variable

Step 1 Press Ctrl+Alt+T to open the Terminal.

Fair Use (screenshot)
\n">

Press Ctrl + Alt + T to open the Terminal. You can open the Terminal using the keyboard shortcut on most Linux distributions. The keyboard shortcut is Ctrl + Alt + T. You can also click the Terminal icon in your Apps menu. It generally has an icon that resembles a black screen with a white text cursor. [3] X Research source

Step 2 Type cd followed by a space and the location the program file is saved to.

Fair Use (screenshot)
\n">

Type cd followed by a space and the location the program file is saved to. If the program launch file is saved to a location that is not in your $PATH variable, then you will need to navigate to that location inside the Terminal. You can do so using the "cd" command. For example, if you have folder for Python programs saved in your "Documents" folder, you can navigate to it in the Terminal by typing cd ~/Documents/Python or something similar, and then press Enter.

Step 3 Type chmod a+x [filename] and press ↵ Enter.

Fair Use (screenshot)
\n">

Type chmod a+x [filename] and press ↵ Enter . Replace "filename" with the actual launch file of the program. The "chmod a+x" command tells Linux the file is an executable file. [4] X Research source

Step 4 Type

Fair Use (screenshot)
\n">

Type "./" followed by the launch filename and press ↵ Enter . This launches the program. For example, if you have a Python file called "Helloworld.py", you would type ./helloworld.py to launch the file.

Advertisement Method 3 of 4:

Adding a Directory to your $PATH Variable

Step 1 Press Ctrl+Alt+T to open the Terminal.

Fair Use (screenshot)
\n">

Press Ctrl + Alt + T to open the Terminal. If you cannot run a program by simply typing the program's name, you may need to add the directory that the program is installed in to your $PATH variable. You can do this from the Terminal as well. Use the keyboard shortcut to open the Terminal if you haven't already done so. [5] X Research source

Step 2 Type the command to export the programs directory to the $PATH variable.

Fair Use (screenshot)
\n">

Step 3 Type nano ~/.bashrc and press ↵ Enter.

Fair Use (screenshot)
\n">

Type nano ~/.bashrc and press ↵ Enter . This opens the ".bashrc" file in a text editor that is based in the Terminal. You can use this file to permanently add the directory to your $PATH variable.

Step 4 Add the

Fair Use (screenshot)
\n">

Add the "export PATH" command to the file. To do so, scroll down to the bottom of the file using the mouse wheel and type export PATH=$PATH:[path/to/program] at the bottom. Replace "[path/to/program]" with the actual directory tree the program is installed in. [6] X Research source

Step 5 Press Ctrl+X.

Fair Use (screenshot)
\n"> Press Ctrl + X . This exits the text editor. It will ask if you want to save the file.

Step 6 Press Y and press ↵ Enter.

Fair Use (screenshot)
\n">

Press Y and press ↵ Enter . This confirms that you want to save and exit the text editor. You will be returned to the standard command prompt in the Terminal.

Step 7 Type source ~/.bashrc and press ↵ Enter.

Fair Use (screenshot)
\n">

Type source ~/.bashrc and press ↵ Enter . This loads the updated $PATH variable into your current session. [7] X Research source

Step 8 Type the name of the program and press ↵ Enter.

Fair Use (screenshot)
\n">

Type the name of the program and press ↵ Enter . With the program's directory now added to your $PATH variable, you should be able to launch the program by simply typing the program name and pressing Enter.

Advertisement Method 4 of 4:

Installing and Uninstalling a Program in the Terminal

Step 1 Press Ctrl+Alt+T to open the Terminal.

Fair Use (screenshot)
\n">

Press Ctrl + Alt + T to open the Terminal. In addition to launching programs from within the Terminal, you can also install and uninstall programs from within the Terminal. Use the keyboard shortcut to open the Terminal if you haven't already done so. [8] X Research source

Step 2 Type sudo apt install [app_name] and press ↵ Enter (Debian).

Fair Use (screenshot)
\n">

Type sudo apt install [app_name] and press ↵ Enter (Debian). Replace "[app_name]" with the actual name of the program you want to install. This command works in Debian-based Linux distributions, such as Ubuntu, and Mint. [9] X Research source

Step 3 Type sudo apt remove [app_name] and press ↵ Enter (Debian).

Fair Use (screenshot)
\n">

Type sudo apt remove [app_name] and press ↵ Enter (Debian). Replace "[app_name]" with the name of the app you want to uninstall. This command works in Debian-based Linux distributions, such as Ubuntu, and Mint.

Step 4 Type sudo dnf install [app_name] and press ↵ Enter (Red Hat).

Fair Use (screenshot)
\n">

Type sudo dnf install [app_name] and press ↵ Enter (Red Hat). Replace "[app_name]" with the actual name of the program you want to install. This command works for Red Hat Linux distributions such as RHEL, Fedora, and CentOS. [10] X Research source

Step 5 Type sudo dnf remove [app_name] and press ↵ Enter (Red Hat).

Fair Use (screenshot)
\n">

Type sudo dnf remove [app_name] and press ↵ Enter (Red Hat). Replace "[app_name]" with the name of the app you want to uninstall. This command works for Red Hat Linux distributions such as RHEL, Fedora, and CentOS. [11] X Research source

Step 6 Type the name of the program and press ↵ Enter.

Fair Use (screenshot)
\n">

Type the name of the program and press ↵ Enter . Once the program is installed, you can launch the program by simply typing the program's name and pressing Enter in the Terminal.

Advertisement

Expert Q&A

Ask a Question 200 characters left Include your email address to get a message when this question is answered. Advertisement

Tips

Submit a Tip All tip submissions are carefully reviewed before being published Please provide your name and last initial Thanks for submitting a tip for review!

You Might Also Like

Change Code on Schlage Lock

How to Change 4-Digit User Codes on Schlage Locks

Format Text as Code in Discord

2 Simple Ways to Format Text Into Code on Discord

Convert from Binary to Decimal

Converting Binary to Decimal: Positional Notation & Doubling

Reset Schlage Keypad Lock Without Programming Code

How to Factory Reset a Schlage Lock & Restore the Default Programming Code

Delay a Batch File

How to Delay a Batch File: Timeout, Pause, Ping, Choice & Sleep

Write Pseudocode

Learn to Write Pseudocode: What It Is and Why You Need It

Make an Exe File

Make an Exe File

Make a Program Using Notepad

Make a Program Using Notepad

Download a GitHub Folder

3 Ways to Download GitHub Directories and Repositories

Convert from Decimal to Hexadecimal

Convert from Decimal to Hexadecimal: A Quick Guide + Examples

View Source Code

How to View Source Code

Update R

How to Update R in RStudio or Manually: Step-by-Step Guide