Running code in Atom requires installing packages and using the built-in terminal or script runner. But if you are new to Linux, figuring out how to run executable file in linux can feel confusing at first. Dont worry, it is simpler than it looks. This guide will walk you through every method, from the terminal to the graphical interface, so you can run any program or script with confidence.
Executable files are the backbone of Linux software. They can be compiled programs, shell scripts, or Python scripts. Unlike Windows, Linux does not rely on file extensions like .exe. Instead, it uses file permissions to decide if a file can run. Once you understand this, you will be able to run almost anything.
What Is An Executable File In Linux
An executable file is a file that the system can run as a program. In Linux, this includes binaries (compiled code) and scripts (text files with a shebang line). The key is that the file must have the “execute” permission set. Without it, even a valid program will not run.
You can check if a file is executable by looking at its permissions. Use the command ls -l filename. If you see an “x” in the permission string (like -rwxr-xr-x), the file is executable. If not, you need to add the permission.
How To Run Executable File In Linux
Now we get to the core of the topic. There are several ways to run an executable file in Linux. The most common is using the terminal, but you can also use the file manager. Below, I break down each method step by step.
Method 1: Using The Terminal With A Dot Slash
This is the standard way to run a file in the current directory. Open your terminal and navigate to the folder containing the executable. Then type:
./filename
The dot and slash tell the system to look in the current directory. Without it, Linux will search your PATH variable, which usually does not include the current folder for security reasons.
For example, if you have a file called “myapp” in your Downloads folder, you would do:
cd ~/Downloads
./myapp
If you get a “Permission denied” error, the file is not executable. Fix it with:
chmod +x myapp
Then try running it again.
Method 2: Running From Anywhere Using Full Path
You do not have to be in the same directory. Just provide the full path to the file. For instance:
/home/username/Downloads/myapp
This works the same as the dot slash method. It is useful when you are working in a different directory and do not want to change folders.
Method 3: Using The File Manager (GUI)
If you prefer a graphical interface, most Linux file managers let you run executables with a double-click. However, this depends on your desktop environment. Here is how it typically works:
- Open your file manager (Nautilus, Dolphin, Thunar, etc.)
- Navigate to the executable file
- Double-click it
- A dialog may ask if you want to “Run” or “Run in Terminal”
- Choose the option that fits
Some file managers hide the “Run” option if the file is not marked as executable. In that case, right-click the file, go to Properties, and under Permissions, check “Allow executing file as program”. Then double-click again.
Method 4: Running Scripts With Shebang
Scripts (like Python, Bash, or Perl) need a shebang line at the top. This tells the system which interpreter to use. For example, a Python script starts with:
#!/usr/bin/env python3
After making the script executable with chmod +x, you can run it like any other program. Just type:
./script.py
Or use the full path. The system reads the shebang and runs the correct interpreter automatically.
Method 5: Using The “Sh” Or “Bash” Command
If you do not want to set execute permissions, you can run a script directly with the shell. For a Bash script:
bash script.sh
For a Python script:
python3 script.py
This method bypasses the need for the execute bit. It is handy for quick testing, but not ideal for production use.
Setting Execute Permissions With Chmod
Before you can run any file, it must have the execute permission. The chmod command is your friend. Here are the most common ways to use it:
chmod +x filename– Adds execute permission for everyonechmod u+x filename– Adds execute only for the file ownerchmod 755 filename– Sets rwx for owner, rx for group and others
You can check the result with ls -l. The “x” will appear in the permission string.
Common Errors And How To Fix Them
Even experienced users hit snags. Here are the most frequent issues when trying to run executables:
Error: Permission Denied
This means the file lacks execute permission. Run chmod +x filename and try again.
Error: Command Not Found
This happens when you type the filename without the dot slash. Always use ./filename for files in the current directory.
Error: No Such File Or Directory
Check your spelling and path. Use pwd to see your current directory, then ls to list files.
Error: Binary File Executable Format Error
You might be trying to run a file built for a different architecture (e.g., 32-bit on a 64-bit system). Install the necessary libraries or get the correct version.
Running Executables From A Different Directory
Sometimes you want to run a program without typing the full path every time. You can add the program’s directory to your PATH variable. Edit your shell configuration file (like ~/.bashrc or ~/.zshrc) and add:
export PATH=$PATH:/path/to/your/program
Then reload with source ~/.bashrc. Now you can run the program by just typing its name.
Running Executables As Root
Some programs need root privileges. Use sudo before the command:
sudo ./filename
Be careful with this. Running unknown files as root can damage your system. Only do it when you trust the source.
Running Executables In The Background
If you want to run a program and keep using the terminal, append an ampersand:
./filename &
The program runs in the background. You can bring it back to the foreground with the fg command.
Running Executables From A Script
You can run other executables inside a shell script. Just call them normally:
#!/bin/bash
./myapp
echo "Done"
Make the script executable and run it. This is useful for automation.
Using The “Run” Dialog (Alt+F2)
Most Linux desktops have a quick run dialog. Press Alt+F2, type the full path to the executable, and press Enter. This works even if the file is not in your PATH.
Running Windows Executables On Linux
You cannot run Windows .exe files directly on Linux. But you can use Wine or a virtual machine. Wine translates Windows API calls to Linux. Install it with:
sudo apt install wine
Then run the .exe file:
wine program.exe
Not all programs work, but many do.
Security Tips For Running Executables
Only run files from trusted sources. Malware exists on Linux, though it is less common. Always verify the file’s origin. Use sha256sum to check checksums if available. Avoid running scripts with sudo unless necessary.
Frequently Asked Questions
How Do I Make A File Executable In Linux?
Use the chmod +x filename command. This adds the execute permission for all users.
Why Do I Need To Use ./ To Run A File?
Linux does not include the current directory in the PATH for security. The dot slash tells the system to look in the current folder.
Can I Run A .Exe File On Linux?
Not directly. Use Wine or a virtual machine to run Windows executables.
What Does “Chmod 755” Mean?
It sets read, write, and execute for the owner, and read and execute for group and others. It is a common permission for executables.
How Do I Run A Python Script As An Executable?
Add a shebang line (#!/usr/bin/env python3) at the top, make the file executable with chmod +x, then run it with ./script.py.
Conclusion
Now you know how to run executable file in linux using multiple methods. Start with the terminal and dot slash for most tasks. Use the file manager for a graphical approach. Remember to set execute permissions with chmod first. With practice, running any program becomes second nature. If you hit an error, check permissions, paths, and file types. Linux gives you full control, but it also expects you to understand the basics. You have got the knowledge now, so go ahead and run that file.