If you are new to Linux, you might wonder how to run programs in Linux. Running programs in Linux efficiently depends on understanding file permissions and the system’s PATH variable. Unlike Windows, where you double-click an executable, Linux gives you more control through the terminal and graphical interfaces. This guide walks you through every method, from simple clicks to advanced command-line tricks.
Let’s start with the basics. You can run a program by typing its name in the terminal. But first, you need to know where it lives. The shell looks for programs in directories listed in the PATH variable. If the program is not in PATH, you must specify the full path.
Understanding File Permissions
Before you run anything, check if the file is executable. Linux uses permissions to control who can read, write, or execute a file. Use the ls -l command to see permissions. The output shows something like -rwxr-xr-x. The x means execute permission.
If you see no x, you cannot run the file. Use chmod +x filename to add execute permission. For example, chmod +x myscript.sh makes a script executable. You can also use numeric modes like chmod 755.
Checking Current Permissions
Type ls -l myprogram to see its permissions. The first character is the file type. The next nine characters are three sets of three: owner, group, and others. Each set has r (read), w (write), and x (execute).
-rwxr--r--means owner can read, write, execute; group and others can only read.-rwx------means only owner can do everything.
If you own the file, use chmod to change permissions. If you don’t, use sudo or ask the admin.
Running Programs From The Terminal
The terminal is the most direct way. Open it from your applications menu or press Ctrl+Alt+T. Then type the program name and press Enter. If the program is in PATH, it runs immediately.
Common PATH directories include /usr/bin, /bin, and /usr/local/bin. To see your PATH, type echo $PATH. Each directory is separated by a colon.
Using Relative And Absolute Paths
If the program is in your current directory, use ./programname. The dot means current directory. For example, ./myapp runs a file in the folder you are in. An absolute path starts from root, like /home/user/myapp.
To run a script, you might need to specify the interpreter. For Python scripts, use python3 script.py. For bash scripts, use bash script.sh or make it executable and run ./script.sh.
Example: Running A Python Script
- Create a file named
hello.pywithprint("Hello"). - Make it executable:
chmod +x hello.py. - Run it:
./hello.py.
If the script has a shebang line (#!/usr/bin/python3), Linux knows which interpreter to use. Without it, you must call the interpreter manually.
How To Run Programs In Linux Using The GUI
Not everyone likes the terminal. Linux desktop environments like GNOME, KDE, or XFCE let you run programs with a click. Look for the application menu or launcher. Type the program name in the search bar.
You can also create desktop shortcuts. Right-click on the desktop, choose “Create Launcher,” and fill in the command. For example, to run Firefox, type firefox in the command field.
Running Programs From The File Manager
Open the file manager and navigate to the program. Double-click an executable file. If it’s a binary, it may run directly. For scripts, the system might ask what to do. Choose “Run” or “Execute.”
Some file managers require you to enable “Execute” in the file’s properties. Right-click, go to Permissions, and check “Allow executing file as program.”
Managing The PATH Variable
The PATH variable tells the shell where to find executables. If you install a program in a custom location, add that directory to PATH. Otherwise, you must type the full path every time.
To add a directory temporarily, use export PATH=$PATH:/new/directory. This change lasts only for the current terminal session. To make it permanent, add the export line to your shell configuration file, like ~/.bashrc or ~/.zshrc.
Editing Bashrc For Permanent PATH Changes
- Open
~/.bashrcin a text editor:nano ~/.bashrc. - Add a line:
export PATH=$PATH:/home/yourname/bin. - Save and exit. Then run
source ~/.bashrcto apply changes.
Now you can run programs from that directory by just typing their name.
Running Programs With Sudo
Some programs need root privileges. Use sudo before the command. For example, sudo apt update runs the package manager as root. Be careful: sudo gives full system access.
You can also run graphical programs with sudo, but it’s not recommended. Instead, use gksudo or pkexec for GUI apps. These tools avoid permission issues.
When To Use Sudo
- Installing software:
sudo apt install vlc. - Editing system files:
sudo nano /etc/hosts. - Running system commands:
sudo systemctl restart nginx.
Never run everyday programs with sudo. It can break file permissions and cause security risks.
Running Background Processes
Sometimes you want a program to keep running after you close the terminal. Use the ampersand (&) at the end of the command. For example, firefox & launches Firefox in the background.
To bring a background job to the foreground, use fg. To list all background jobs, use jobs. You can also use nohup to ignore hangup signals: nohup myprogram &.
Using Screen Or Tmux
For long-running tasks, use terminal multiplexers like screen or tmux. They let you detach and reattach sessions. Install them with sudo apt install screen or tmux.
- Start a screen session:
screen -S mysession. - Run your program.
- Detach with
Ctrl+Athend. - Reattach later:
screen -r mysession.
Running Programs From Different Directories
You can run a program from anywhere if it’s in PATH. But if it’s not, use the full path. For example, /opt/myapp/bin/start. You can also create a symbolic link in a PATH directory.
To create a symlink: sudo ln -s /opt/myapp/bin/start /usr/local/bin/myapp. Now you can run myapp from any location.
Using Alias For Shortcuts
Aliases let you create short commands. Add them to ~/.bashrc. For example: alias ll='ls -la'. Then type ll to run the long listing.
You can also alias a program with options: alias myapp='/opt/myapp/bin/start --verbose'.
Running Programs With Arguments
Most programs accept arguments. For example, ls -l /home lists files in the home directory. Arguments follow the program name, separated by spaces.
If an argument contains spaces, enclose it in quotes: cat "my file.txt". You can also use escape characters: cat my\ file.txt.
Passing Options And Flags
Options usually start with a dash. Short options use one dash: -a. Long options use two dashes: --all. Combine short options: ls -la is same as ls -l -a.
Some programs require arguments for options: gcc -o outputfile source.c. Always check the program’s help with --help or man programname.
Running Programs In Different Runlevels
Linux systems have runlevels that define which services run. You can start programs at boot using systemd services. Create a service file in /etc/systemd/system/.
For example, a simple service file:
[Unit] Description=My App [Service] ExecStart=/usr/bin/myapp Restart=always [Install] WantedBy=multi-user.target
Then enable it: sudo systemctl enable myapp. Start it: sudo systemctl start myapp.
Running Programs At Login
Add commands to ~/.profile or ~/.bash_profile to run them when you log in. For GUI autostart, place a .desktop file in ~/.config/autostart/.
Common Issues And Fixes
Sometimes programs won’t run. Here are frequent problems and solutions:
- Command not found: The program is not in PATH. Install it or use the full path.
- Permission denied: The file is not executable. Run
chmod +x. - No such file or directory: The path is wrong. Double-check the location.
- Segmentation fault: The program crashed. Check for updates or missing libraries.
Use file command to identify the file type. For example, file myprogram tells you if it’s an ELF binary, script, or something else.
Debugging With Strace
If a program fails silently, use strace to trace system calls. Install it with sudo apt install strace. Then run strace ./myprogram to see what happens.
Running Programs In Containers
Containers like Docker let you run programs in isolated environments. Install Docker, then pull an image and run it. For example, docker run hello-world.
You can also run GUI apps in containers with X11 forwarding. This is advanced but useful for testing.
Using Flatpak And Snap
Flatpak and Snap are package managers that sandbox applications. Install them with sudo apt install flatpak or snapd. Then run programs like flatpak run org.gimp.GIMP or snap run firefox.
How To Run Programs In Linux For Beginners
Start with the GUI. Open the application menu and click. For custom programs, use the terminal. Remember these steps:
- Make sure the file is executable:
chmod +x filename. - If it’s in the current directory, run
./filename. - If it’s in PATH, just type the name.
- Use
sudoonly when needed.
Practice with simple commands like ls, pwd, and echo. Then move to running scripts and installed software.
Frequently Asked Questions
How Do I Run A .Sh File In Linux?
Make it executable with chmod +x file.sh, then run ./file.sh. Or use bash file.sh.
What Does ./ Mean In Linux?
The dot-slash (./) means the current directory. It tells the shell to look for the program in the folder you are in.
Can I Run Windows Programs On Linux?
Yes, using Wine or a virtual machine. Wine runs many Windows apps, but not all. For full compatibility, use a VM.
Why Does My Program Say “Command Not Found”?
The program is not in your PATH. Either install it, use the full path, or add its directory to PATH.
How Do I Run A Program In The Background?
Add an ampersand at the end: programname &. Use jobs to see background tasks and fg to bring them forward.
Final Tips For Running Programs Smoothly
Always check file permissions first. Use ls -l to see them. If you get errors, read the message carefully. Most Linux errors tell you exactly what’s wrong.
Keep your system updated. Use sudo apt update && sudo apt upgrade to get latest versions. This fixes many compatibility issues.
Experiment with different methods. The terminal gives you power, but the GUI is fine for everyday tasks. Over time, you’ll find what works best for you.
Remember that Linux is flexible. You can run programs from the command line, desktop, scripts, or even remotely via SSH. Each method has its place. Start simple and build your skills.
With practice, running programs becomes second nature. You’ll learn to troubleshoot, automate, and customize your workflow. The key is to understand permissions, PATH, and the tools available.
Now you know how to run programs in Linux. Go ahead and try it. Open a terminal, type a command, and see what happens. The more you practice, the more confident you’ll become.