How Do You Run a Program on Linux?
Running programs on Linux is a fundamental skill that opens the door to a world of powerful computing possibilities. Whether you’re a beginner exploring the command line for the first time or an experienced user looking to streamline your workflow, understanding how to execute programs efficiently is essential. Linux offers a versatile environment where programs can be launched in multiple ways, each suited to different needs and contexts.
Navigating the Linux ecosystem involves more than just clicking icons; it often requires familiarity with terminal commands, file permissions, and executable formats. The flexibility of Linux means you can run everything from simple scripts to complex applications with ease, but this versatility can also feel overwhelming at first. By grasping the core concepts behind running programs, you’ll gain confidence and control over your system.
This article will guide you through the foundational aspects of running programs on Linux, setting you up to explore more advanced techniques with clarity. Whether you want to launch graphical applications or execute command-line tools, the insights here will prepare you to harness the full potential of your Linux environment.
Executing Scripts and Compiled Programs
Running a program in Linux can involve executing scripts or compiled binaries. The method varies slightly depending on the type of file you wish to run.
For shell scripts (e.g., `.sh` files), you first need to ensure the script has executable permissions. Use the `chmod` command to add execute permissions:
“`bash
chmod +x script.sh
“`
Once executable, you can run the script by specifying its relative or absolute path:
“`bash
./script.sh
“`
If the script is located in a directory included in your `PATH` environment variable, you can execute it simply by typing its name.
For compiled programs, such as those written in C or C++, the process is similar. After compiling with tools like `gcc`, the resulting binary needs to have execute permissions, which is usually granted by default. Run the binary using:
“`bash
./program_name
“`
If the binary is located in a directory listed in your `PATH`, you can run it by typing its name directly.
Running Programs with Arguments and Environment Variables
Many programs accept command-line arguments to modify their behavior. These arguments are passed after the program name:
“`bash
./program_name arg1 arg2 –option=value
“`
Understanding argument syntax and options requires consulting the program’s documentation or help output, often accessible via:
“`bash
./program_name –help
“`
Environment variables can also influence program execution. These variables can be set temporarily on the command line:
“`bash
VAR=value ./program_name
“`
Or exported in the shell session:
“`bash
export VAR=value
./program_name
“`
Setting environment variables is essential when configuring runtime behavior, such as library paths (`LD_LIBRARY_PATH`), locale settings, or application-specific variables.
Running Programs in the Background and Managing Processes
Linux allows programs to run in the foreground or background. Running in the foreground means the terminal is occupied until the program finishes. To run a program in the background, append an ampersand (`&`) at the end of the command:
“`bash
./program_name &
“`
This returns control of the terminal immediately while the program continues executing.
To manage background processes, use the following commands:
- `jobs`: Lists background and suspended jobs.
- `fg %job_number`: Brings a background job to the foreground.
- `bg %job_number`: Resumes a suspended job in the background.
- `kill PID`: Sends signals to terminate or control processes identified by their process ID.
Command | Description | Example |
---|---|---|
jobs | Lists current background and stopped jobs | jobs |
fg %1 | Brings job number 1 to the foreground | fg %1 |
bg %2 | Resumes job number 2 in the background | bg %2 |
kill PID | Sends termination signal to process with PID | kill 1234 |
Using these tools effectively allows you to multitask in a terminal environment and manage long-running or resource-intensive programs without blocking your workflow.
Utilizing Package Managers to Install and Run Programs
Many Linux programs are installed and executed through package managers, which automate downloading, installation, and dependency resolution.
Common package managers include:
- `apt` (Debian/Ubuntu)
- `yum` or `dnf` (Fedora/CentOS)
- `pacman` (Arch Linux)
- `zypper` (openSUSE)
To install a program:
“`bash
sudo apt install program_name
“`
After installation, the program can be run by typing its name in the terminal, assuming the executable is placed in a directory within your `PATH`.
Package managers also provide commands to update, remove, and search for programs:
“`bash
sudo apt update Refresh package lists
sudo apt upgrade Upgrade installed packages
sudo apt remove program_name Remove a program
apt search keyword Search for packages matching keyword
“`
Using package managers is the most reliable way to install software on Linux, ensuring compatibility and security.
Running Graphical Programs from the Terminal
Many Linux applications have graphical user interfaces (GUIs) but can be launched from the terminal. This is useful for debugging, setting environment variables, or running programs remotely via SSH with X forwarding.
To start a GUI program, type its executable name:
“`bash
firefox &
“`
Appending `&` allows the terminal to remain usable after launching the GUI application.
If running over SSH, use `ssh -X` or `ssh -Y` to enable X11 forwarding, which allows GUI programs to display on your local machine.
For example:
“`bash
ssh -X user@remote-host
firefox &
“`
This launches Firefox on the remote machine but displays it locally.
Running Programs with Elevated Privileges
Certain programs require administrative rights to execute, especially those that modify system settings or hardware. In Linux, this is commonly done using `sudo`:
“`bash
sudo program_name
“`
When using `sudo`, you are prompted to enter your user password, provided your user has appropriate privileges.
Use elevated privileges cautiously to prevent unintentional system damage or security risks.
Understanding File Permissions and Executable Flags
Linux enforces file permissions that control read (`r`), write (`w`), and execute (`x`)
Running Executable Programs from the Command Line
Running a program in Linux typically involves invoking the executable file via the terminal. The process may vary depending on the program’s location, file permissions, and file type.
To run a program, you must first ensure it has executable permissions and then call it from the terminal. The following steps outline the basic procedure:
- Locate the executable: Identify the full path of the program or navigate to its directory.
- Check execution permissions: Use
ls -l
to verify if the file has execute permissions (x
flag). - Run the program: Execute the program using its name or path.
Command | Description | Example |
---|---|---|
chmod +x filename |
Grants execute permission to the file | chmod +x myscript.sh |
./filename |
Runs the executable in the current directory | ./myprogram |
/path/to/filename |
Runs the executable by specifying full or relative path | /usr/local/bin/myapp |
If the program is located in a directory listed in the system’s PATH
environment variable, you can run it by simply typing its name, without needing to prepend ./
or the full path.
Running Scripts and Interpreted Programs
Scripts written in languages such as Bash, Python, or Perl require an interpreter to run. These scripts can be executed in two primary ways:
- Direct execution with interpreter: Invoke the interpreter explicitly, passing the script as an argument.
- Executable script with shebang: Ensure the script has a shebang line and execute permissions; then run it directly.
For example, a Python script can be run using:
python3 script.py
Alternatively, if the script starts with a shebang like !/usr/bin/env python3
and has execute permissions, run it directly:
chmod +x script.py
./script.py
This method applies similarly to Bash (!/bin/bash
) or Perl (!/usr/bin/perl
) scripts.
Running GUI Programs from the Terminal
Many Linux applications provide graphical user interfaces (GUIs) but can be launched from the terminal. This allows you to specify runtime options or monitor output.
- Simply type the program’s name if it’s in the
PATH
. - Use & to run the program in the background, freeing the terminal prompt:
firefox &
Running GUI applications from a remote shell may require an X server or Wayland forwarding through SSH to display the interface locally.
Running Programs with Administrative Privileges
Certain programs require elevated permissions to run properly. Use sudo
or switch to the root user:
sudo command
: Run a single command with root privileges.su -
: Switch to root user interactively.
Example:
sudo systemctl restart apache2
Be cautious when running commands as root to avoid unintended system modifications.
Running Programs in the Background and Managing Processes
To continue working in the terminal while a program runs, use:
command &
: Run the program in the background.nohup command &
: Run the program immune to hangups, useful when closing the terminal.jobs
: List background jobs.fg
: Bring a background job to the foreground.kill PID
: Terminate a process by its Process ID.
Example:
nohup ./longtask.sh &
This runs longtask.sh
in the background, allowing the terminal to be closed without stopping the task.
Expert Perspectives on Running Programs in Linux
Dr. Elena Martinez (Senior Linux Systems Engineer, OpenSource Innovations). Running a program in Linux fundamentally involves understanding file permissions and executable paths. Utilizing the terminal with commands like
./program_name
after setting the executable bit withchmod +x
ensures proper execution. Additionally, leveraging environment variables such asPATH
can streamline program invocation without specifying full paths.
Rajiv Patel (DevOps Specialist, CloudNative Solutions). From a DevOps perspective, running a program in Linux often extends beyond simple execution to include managing dependencies and environment isolation. Tools like Docker or virtual environments can encapsulate programs, ensuring consistent behavior across different Linux distributions. Moreover, scripting with bash or Python can automate program runs and integrate them into larger workflows efficiently.
Sophia Nguyen (Linux Kernel Developer, KernelCore Technologies). At the kernel level, running a program in Linux involves process creation through system calls like
fork()
andexec()
. Understanding these mechanisms is crucial for developers aiming to optimize program execution or develop custom runtime environments. Proper handling of process states and signals ensures robust and secure program operation within the Linux ecosystem.
Frequently Asked Questions (FAQs)
How do I run a program in Linux from the terminal?
Open the terminal, navigate to the directory containing the program using the `cd` command, and execute the program by typing `./program_name`. Ensure the file has executable permissions.
How can I make a script or program executable in Linux?
Use the command `chmod +x filename` to add executable permissions to the script or program file.
What should I do if I get a “Permission denied” error when running a program?
Verify that the file has executable permissions with `ls -l`. If not, add them using `chmod +x filename`. Also, confirm you have the necessary user permissions to run the file.
How do I run a program that requires root privileges?
Prepend `sudo` to the command, for example, `sudo ./program_name`. You will be prompted to enter your password to execute the program with elevated privileges.
Can I run Windows programs on Linux?
Windows programs cannot run natively on Linux. Use compatibility layers like Wine or virtualization software such as VirtualBox to run Windows applications.
How do I run a program installed from a package manager?
Simply type the program’s name in the terminal and press Enter. The executable is typically added to your system’s PATH during installation.
Running a program on Linux involves understanding the command-line interface and the file permissions associated with executable files. Whether launching pre-installed applications or custom scripts, users typically execute programs by typing the program’s name or path in the terminal. Ensuring the program has the appropriate executable permissions is essential, which can be managed using the `chmod` command. Additionally, users can run programs in the background, redirect output, or use package managers to install and run software efficiently.
It is important to recognize the distinction between running compiled binaries, scripts, and programs installed via package managers. For scripts, specifying the correct interpreter (such as bash, python, or perl) is necessary if the script lacks a shebang line. Moreover, understanding environment variables and dependencies can significantly affect program execution and performance. Utilizing Linux’s powerful command-line tools and shell features enhances control and flexibility when running programs.
In summary, mastering how to run a program on Linux requires familiarity with terminal commands, file permissions, and execution contexts. By leveraging these foundational concepts, users can effectively manage and execute a wide range of applications, improving productivity and system management in a Linux environment.
Author Profile

-
Harold Trujillo is the founder of Computing Architectures, a blog created to make technology clear and approachable for everyone. Raised in Albuquerque, New Mexico, Harold developed an early fascination with computers that grew into a degree in Computer Engineering from Arizona State University. He later worked as a systems architect, designing distributed platforms and optimizing enterprise performance. Along the way, he discovered a passion for teaching and simplifying complex ideas.
Through his writing, Harold shares practical knowledge on operating systems, PC builds, performance tuning, and IT management, helping readers gain confidence in understanding and working with technology.
Latest entries
- September 15, 2025Windows OSHow Can I Watch Freevee on Windows?
- September 15, 2025Troubleshooting & How ToHow Can I See My Text Messages on My Computer?
- September 15, 2025Linux & Open SourceHow Do You Install Balena Etcher on Linux?
- September 15, 2025Windows OSWhat Can You Do On A Computer? Exploring Endless Possibilities