Execute programs in linux

How to Run a Program from the Command Line on Linux

This article was co-authored by wikiHow staff writer, Travis Boylls. Travis Boylls is a Technology Writer and Editor for wikiHow. Travis has experience writing technology-related articles, providing software customer service, and in graphic design. He specializes in Windows, macOS, Android, iOS, and Linux platforms. He studied graphic design at Pikes Peak Community College.

The wikiHow Tech Team also followed the article’s instructions and verified that they work.

This article has been viewed 278,602 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.

Running a Program From the Terminal

Image titled Run a Program from the Command Line on Linux Step 1

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.

Image titled Run a Program from the Command Line on Linux Step 2

  • For example, if you want to run Firefox from the Terminal, you would simply type firefox and press Enter.
  • Type -h or —help after the program name to display the help menu for that program. Many programs have additional command modifiers you can use to launch the program in a specific way. For example, you can launch a website in a web browser by typing the web browser name followed by the web address and press Enter to launch that website in the web browser (i.e. firefox www.wikihow.com .
  • If you receive a message that says you don’t have permission to run a program or access is denied, type sudo before the program name and press Enter. The «sudo» command allows regular users to run Terminal commands with administrative privileges or root access.
  • If you want to run a C or C++ program from the Terminal, you will first need to complie the program before you can launch it from the Terminal.

Running a Program Outside the $PATH Variable

Image titled Run a Program from the Command Line on Linux Step 3

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.

Image titled Run a Program from the Command Line on Linux Step 4

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.

Читайте также:  Acunetix web scanner linux

Image titled Run a Program from the Command Line on Linux Step 5

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. [1] X Research source

Image titled Run a Program from the Command Line on Linux Step 6

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. [2] X Research source

Adding a Directory to your $PATH Variable

Image titled Run a Program from the Command Line on Linux Step 7

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.

Image titled Run a Program from the Command Line on Linux Step 8

  • For example, if you have a program installed in the «bin» directory of your «Home» folder, you would type export PATH=$PATH:$Home/bin and press Enter. This will temporarily add the «$Home/bin» directory to your $PATH variable.
  • You can see which directories are currently added to your $PATH variable by typing the command echo $PATH and pressing Enter.

Image titled Run a Program from the Command Line on Linux Step 9

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.

Image titled Run a Program from the Command Line on Linux Step 10

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. [3] X Research source

Image titled Run a Program from the Command Line on Linux Step 11

Image titled Run a Program from the Command Line on Linux Step 12

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.

Image titled Run a Program from the Command Line on Linux Step 13

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

Image titled Run a Program from the Command Line on Linux Step 14

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.

Installing and Uninstalling a Program in the Terminal

Image titled Run a Program from the Command Line on Linux Step 15

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.

Image titled Run a Program from the Command Line on Linux Step 16

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.

Image titled Run a Program from the Command Line on Linux Step 17

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.

Image titled Run a Program from the Command Line on Linux Step 18

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.

Image titled Run a Program from the Command Line on Linux Step 19

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. [5] X Research source

Читайте также:  Vipnet for linux руководство администратора

Image titled Run a Program from the Command Line on Linux Step 20

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.

Expert Q&A

Tips

You Might Also Like

Convert from Binary to Decimal

Format Text as Code in Discord

Change Code on Schlage Lock

How to Change 4-Digit User Codes on Schlage Locks

Delay a Batch File

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

Reset Schlage Keypad Lock Without Programming Code

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

Write Pseudocode

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

Download a File from GitHub

Code

Make an Exe File

View Source Code

Start Learning Computer Programming

How to Start Coding: The Beginner’s Guide to Programming

Make a Program Using Notepad

Download a GitHub Folder

3 Ways to Download GitHub Directories and Repositories

Источник

Brilliant Ways on How to Run a Program in Linux

If you are new to Linux, particularly the command line, and want to learn how to run a program in Linux, you’ve come to the right spot. Running programs in Linux is no different than how it’s done in Windows. Easy to say, right? But no worries, you’ll get to run any program in no time.

In this tutorial, you’ll learn many ways to run programs in Linux, both via GUI and a command-line environment. From a novice Linux user to a power user, you will find knowing these methods to run a program helpful.

Prerequisites

Ubuntu Desktop 15.04 or later – Ensure you have a Linux host ready to go. This tutorial uses Ubuntu 15.04 (Desktop version) with GNOME installed, but any newer distribution should work similarly.

Launching Programs with the Application (App) Launcher

There are generally multiple ways to run a program within Windows, and Linux is no different. We will start with the most common way to run a program using the Launcher.

The most common method to run programs in Linux is to use the Launcher. The Launcher is a bar similar to the Windows start menu that contains a list of icons you can click on to run programs.

In Ubuntu, the App Launcher is located on the left side of the screen, as you can see below, containing default commonly run applications. To open the program, simply click the icon representing the program.

Accessing the Launcher programs through GUI

Launching Programs with the Applications Menu (Unity Dash)

You can also run programs in Ubuntu Linux with Unity Dash. The Applications Menu or Unity Dash is a handy way to search for and run programs in GNOME. To use the Applications Menu, click on the Ubuntu button in the top left corner.

Selecting the icon to search and launch programs using the Unity Dash

You’ll see below that the menu opens a search bar with any recently run programs.

Search for the program you want to run using the Unity Dash in older versions of Ubuntu

Type in the correct name of the program you are looking for (i.e Firefox) and it will appear, then select it to launch the program.

In Ubuntu Linux v20.04+, Unity Dash has been replaced with Activities in the upper left of your screen but the process to run a program remains the same.

Using the Run Command to Launch Program

Another way to launch programs in Linux is to use the Run command. The Run command is a handy way to quickly run a program in Linux by typing the program and executing it.

To run programs via the Run command, select the Alt-F2 to open the Run Command box.

You can also hit Alt-F2 as a shortcut to the run command.

Using the run command

Next, type the name of the program you want to run. In this example, you’ll run the Terminal application, type terminal, select the Terminal icon and hit Enter.

Читайте также:  Joining linux to domain

Selecting the icon or hitting enter will launch the program

You’ll see below that Linux will launch the Terminal application.

Running Programs Using Hot Keys

If you’re more of a keyboard ninja and would rather skip the mouse like we started with in the last example, you can also run programs with hotkeys. In all Linux distros, you can use the Super Key (Windows Key) + A. The Super Key will bring up all applications in alphabetical order and a text box to type in the name of a program, as shown below.

You can type the name of the program in the search box to navigate to the program or click on the program with your mouse if it appears immediately.

Running Programs Using Hot Keys

Setting Up Keyboard Shortcuts to Run Programs in Linux

Now that you have learned the GUI options to run programs, the remainder of this tutorial will focus on using non-GUI-based options to run programs. Let’s first begin with keyboard shortcuts. Using keyboard shortcuts can remove a lot of clicking around.

To set up keyboard shortcuts in Ubuntu:

1. Select the icon in the top left corner again and Keyboard Shortcut. The Keyboard application should show up below. When it does, click on it.

Selecting the icon and launching the Keyboard Shortcut

2. In the Keyboard application, click on the Shortcut tab.

In Ubuntu 20.04 and newer, selecting Keyboard Shortcut from the Activities menu brings you directly to the Shortcuts tab.

Accessing the Shortcuts Tab

3. Click on the + icon to create a new keyboard shortcut. Ubuntu will direct you to the Custom Shortcuts section.

Adding a New Shortcut

4. Next, enter a descriptive Name for the shortcut key and provide the Command (program) to execute and click Apply.

Entering the name and program to use for the Shortcut

When Ubuntu creates the shortcut, you’ll see that the Name shows up under Custom Shortcuts but it’s disabled.

Seeing the Created, but not Active Shortcut Key

5. Now, click on the Disabled text as shown above and press the desired keyboard shortcut such as Ctrl+T. Once you type your desired shortcut, it will show up, as shown below.

Activating the Shortcut

6. Finally, launch the application by pressing the keyboard shortcut!

Running a Program within the Terminal

Although if you’re a newcomer to Linux, chances are you’ll be running programs with the GUI but if you need to use the command line for any reason, the Terminal makes it easy to do so. The Terminal is a command-line application that allows you to manage all facets of Linux with the keyboard.

To run programs in the Terminal, open the App Launcher (or Activities) in the upper left corner and run the Terminal application as shown below.

Accessing the Terminal

When the Terminal opens, as shown below, simply type the name of the program and press Enter.

Running programs in the Terminal will not work for all programs. Some programs may not be in the PATH.

Launching the program end result

Conclusion

In this tutorial, you’ve learned many different methods to run programs in Linux. Using both GUI-based and command-line-based methods, you should now know how to launch programs wherever you are within Linux.

Try installing programs in Linux such as the tutorial to install a common program such as Docker for practice and then run it using a shortcut, command line, or GUI Interface. Which way will you use most often to run your favorite programs?

Hate ads? Want to support the writer? Get many of our tutorials packaged as an ATA Guidebook.

Источник

Оцените статью
Adblock
detector