Running a program on Linux often means specifying its full path or adding it to your PATH. If you’re new to Linux, understanding how to run a program on Linux can feel confusing at first, but it’s actually quite simple once you know the basics. This guide walks you through every method step by step, so you can start any application or script with confidence.
Linux offers several ways to launch programs: from the terminal, using file managers, or through desktop shortcuts. Each method has its own use case, and we’ll cover them all. By the end, you’ll know exactly how to handle any executable file.
How To Run A Program On Linux
Understanding Executable Files In Linux
Before running anything, you need to know what makes a file executable. In Linux, a program is just a file with execute permission. Unlike Windows, Linux doesn’t rely on file extensions like .exe to determine runnability.
Check if a file has execute permission by running ls -l filename. If you see an ‘x’ in the permissions column (like -rwxr-xr-x), it’s executable. If not, you can add permission with chmod +x filename.
Common executable types include:
- Binary programs (compiled from C, C++, Rust, etc.)
- Scripts (Bash, Python, Perl, etc.)
- AppImage or Flatpak packages
- Java JAR files (require Java runtime)
Method 1: Running From The Terminal
The terminal is the most direct way to run programs. Here’s how to do it for different scenarios.
Running A Program In The Current Directory
If you’re in the same folder as the program, type ./programname. The dot-slash tells Linux to look in the current directory.
- Open a terminal (Ctrl+Alt+T on most distributions).
- Navigate to the folder:
cd /path/to/program. - Make it executable if needed:
chmod +x programname. - Run it:
./programname.
For example, if you downloaded a script called “myscript.sh” in your Downloads folder, you’d do:
cd ~/Downloads
chmod +x myscript.sh
./myscript.sh
Running A Program From Anywhere (Using PATH)
If you add a program to your PATH, you can run it by just typing its name. The PATH is a list of directories where Linux looks for executables.
To see your current PATH, type echo $PATH. Common directories include /usr/bin, /usr/local/bin, and ~/.local/bin.
To add a program to your PATH permanently:
- Move the program to a directory already in PATH, like /usr/local/bin:
sudo mv programname /usr/local/bin/. - Or add a new directory to your PATH by editing ~/.bashrc (or ~/.zshrc): add the line
export PATH="$PATH:/path/to/your/directory". - Reload the file:
source ~/.bashrc.
Now you can run the program from anywhere by just typing its name.
Running Programs With Arguments
Many programs accept arguments. Just add them after the program name:
./programname --option value inputfile.txt
For instance, to run a Python script with arguments:
python3 myscript.py --verbose input.csv
Method 2: Using The File Manager (GUI)
Most Linux desktop environments let you run programs by double-clicking them. But you might need to set permissions first.
For Scripts And Binaries
- Right-click the file and select Properties (or Permissions).
- Check “Allow executing file as program” or set the permission to executable.
- Double-click the file. You’ll see options like “Run in Terminal” or “Run”.
- Choose accordingly. For scripts, “Run in Terminal” is often best so you can see output.
For AppImage Files
AppImages are portable Linux applications. Just make them executable and double-click:
- Right-click the AppImage file, go to Properties > Permissions.
- Check “Allow executing file as program”.
- Double-click to launch.
For .deb Or .rpm Packages
These are installation packages, not direct runnable files. Double-clicking them opens your package manager (like GDebi or Software Center) to install the program. After installation, you can run it from the application menu.
Method 3: Using Desktop Shortcuts (.Desktop Files)
Desktop shortcuts make launching programs easy. They’re .desktop files stored in /usr/share/applications or ~/.local/share/applications.
To create one:
- Create a new file ending in .desktop:
nano ~/.local/share/applications/myprogram.desktop. - Add content like:
[Desktop Entry]
Name=My Program
Exec=/path/to/program
Type=Application
Icon=/path/to/icon.png
Terminal=false
- Make it executable:
chmod +x ~/.local/share/applications/myprogram.desktop. - Now it appears in your application menu. You can also drag it to your desktop or panel.
Method 4: Running Programs With Sudo Or As Root
Some programs need root privileges. Use sudo before the command:
sudo ./programname
Or for system-wide installations:
sudo apt install programname
Be careful with sudo—only use it when necessary. Running untrusted programs as root can damage your system.
Method 5: Running Programs In The Background
To run a program and keep using the terminal, append an ampersand (&):
./programname &
To bring it back to the foreground, type fg. To send a running program to the background, press Ctrl+Z then type bg.
For long-running programs, use nohup to keep them running after you close the terminal:
nohup ./programname &
Method 6: Using Package Managers To Install And Run Programs
Most Linux software is installed via package managers. This handles dependencies and creates menu entries automatically.
Debian/Ubuntu (APT)
sudo apt update
sudo apt install firefox
firefox
Fedora (DNF)
sudo dnf install firefox
firefox
Arch Linux (Pacman)
sudo pacman -S firefox
firefox
Snap And Flatpak
These are universal package formats. Install with:
sudo snap install firefox
flatpak install flathub org.mozilla.firefox
Run them from the application menu or terminal using their package name.
Troubleshooting Common Issues
“Command Not Found” Error
This means the program isn’t in your PATH. Either use the full path (like /usr/local/bin/programname) or add its directory to PATH.
“Permission Denied” Error
The file isn’t executable. Use chmod +x filename to fix it.
“No Such File Or Directory”
You might have a typo or the file doesn’t exist. Check the path with ls.
Missing Library Errors
Some programs need shared libraries. Install them via your package manager. For example, if you see “libXYZ.so.6 not found”, search for the package containing it:
apt search libXYZ
Scripts With Windows Line Endings
If you download a script from Windows, it might have carriage returns. Fix with:
sed -i 's/\r$//' script.sh
Running Different Types Of Programs
Python Scripts
Ensure Python is installed. Run with:
python3 script.py
Or make it executable and add a shebang line at the top: #!/usr/bin/env python3.
Bash Scripts
Add #!/bin/bash at the top, make executable, and run with ./script.sh.
Java Programs
Install Java Runtime (JRE). Run JAR files with:
java -jar program.jar
Wine Programs (Windows Executables)
Install Wine, then run .exe files with:
wine program.exe
Best Practices For Running Programs On Linux
- Always verify the source of a program before running it, especially if you use sudo.
- Keep your system updated to avoid security vulnerabilities.
- Use package managers when possible—they handle dependencies and updates.
- For custom scripts, store them in ~/bin or ~/.local/bin and add those to your PATH.
- Use
man programnameorprogramname --helpto learn about options. - When running untrusted code, consider using a container or virtual machine.
Advanced: Running Programs At Startup
To run a program automatically when you log in:
- Open your desktop environment’s startup settings (e.g., GNOME Tweaks, KDE System Settings).
- Add a new startup program with the full command.
- Or manually add a .desktop file to ~/.config/autostart/.
Using Aliases For Frequent Commands
If you run a program with complex arguments often, create an alias in ~/.bashrc:
alias myprog='/path/to/program --option value'
Then just type myprog to run it.
Running Programs From A Different User
Switch users with su or sudo -u username:
sudo -u otheruser ./programname
Frequently Asked Questions
How Do I Run A Program In Linux Terminal?
Type the program’s path or name. If it’s in the current directory, use ./programname. If it’s in your PATH, just type the name.
What Does ./ Mean In Linux?
It means “current directory”. Using ./ before a program name tells Linux to look in the folder you’re currently in.
Why Can’t I Run A Program By Double-clicking It?
You likely need to set execute permission. Right-click the file, go to Properties > Permissions, and check “Allow executing file as program”.
How Do I Run A Program As Root In Linux?
Use sudo ./programname or sudo programname if it’s in your PATH. Be cautious with root access.
What Is The Difference Between Running A Program And Installing It?
Running executes the program immediately. Installing copies files to system directories and often creates menu entries, so you can run it later from anywhere.
Now you have a complete understanding of how to run a program on Linux. Whether you prefer the terminal or a graphical interface, these methods will work for any executable file. Start practicing with simple scripts, and soon you’ll be running complex applications with ease. Remeber to always check permissions and paths if something doesn’t work—it’s usually a small fix. Happy computing on your Linux system!