The -bash: ../binutils-2.38/configure: Permission denied error occurs when the shell attempts to execute a script lacking executable permissions, typically during the GCC build process. This happens because Unix-like systems require explicit execution rights on files, even if they are readable scripts like configure. Resolving this involves verifying file ownership and applying the correct permission bits using standard command-line tools.
Understanding the Root Cause
When you compile software from source, such as building GCC or binutils, you often rely on autoconf-generated scripts. Theconfigure script is a shell script that checks your system's capabilities before generating the Makefile. In Linux and macOS environments, a file must have the execute bit set for the user, group, or others to run it directly. If you downloaded the source code via a method that stripped executable flags (such as some archive extraction methods or network transfers), the system will refuse to run it, throwing the permission denied error.
This issue is distinct from read-only filesystems. If the error were due to a read-only disk, you would typically see "Read-only file system" messages. Here, the specific mention of Permission denied combined with an attempt to run a binary or script points squarely at the mode bits of the file itself. It is also worth noting that while we focus on compilation here, similar permission issues can affect general bash scripting workflows, which are discussed in more detail regarding Bash performance and security configurations.
Step-by-Step Resolution
To fix this, you need to ensure theconfigure script has the executable attribute. Follow these steps carefully within your terminal session.
1. Navigate to the Source Directory
First, ensure you are in the correct directory where the source code was extracted. You should see theconfigure file listed when you run ls.
cd path/to/binutils-2.38
ls -l configure
Look at the output. A typical readable but non-executable file looks like this: -rw-r--r--. An executable file looks like -rwxr-xr-x. Notice the 'x' characters, which stand for execute.
2. Apply Executable Permissions
Use thechmod command to add the execute permission. The most common approach is to make the file executable for the owner, and optionally for the group and others.
chmod +x configure
Alternatively, if you want to be precise about who gets access:
chmod 755 configure
The number 755 means:
- 7 (Owner): Read, Write, Execute
- 5 (Group): Read, Execute
- 5 (Others): Read, Execute
ls -l configure again. You should now see rwxr-xr-x.
3. Run the Configuration Script
Once permissions are corrected, you can proceed with the standard build command. It is crucial to prefix the command with./ to tell the shell to look in the current directory for the executable.
./configure --prefix=/usr/local/gcc-build
If you omit ./, the shell searches your $PATH for a file named configure, which likely does not exist globally, leading to a "command not found" error instead. However, if you still get a permission error after adding ./, double-check that you are not trying to run it as a different user without proper sudo privileges.
Common Pitfalls and Advanced Checks
Sometimes, simply changing permissions isn't enough. If you encounter persistent errors, consider these additional factors.Filesystem Mount Options
Check if your partition is mounted with thenoexec flag. This is common on temporary directories like /tmp or external drives configured for security. Use the mount command to check mount options. If noexec is present, you cannot run scripts there regardless of file permissions. Move your source code to a local home directory or partition without this restriction.
NFS and Network File Systems
If you are compiling on a machine accessing files over NFS, ensure that the server exports the directory withexec permissions. Some older NFS versions default to denying execution for security reasons. Referencing guides on troubleshooting Cygwin permission errors can provide insight into how networked Windows-to-Linux file shares handle execution bits differently than native Linux partitions.
SELinux Contexts
On systems with SELinux enabled (common in RHEL, CentOS, and Fedora), file permissions might look correct, but the security context prevents execution. Check the context withls -Z. If the context is incorrect, you may need to restore it using restorecon -vR . or manually label the file. This is a higher-level security constraint that overrides standard Unix permissions.
Verifying the Build Environment
After resolving the permission issue, it is good practice to clean any previous partial configuration attempts. Runmake clean or remove the generated object files to ensure a fresh start. Then, proceed with make -j$(nproc) to utilize all available CPU cores for faster compilation.
Always monitor the output of ./configure for any warnings about missing dependencies. While permission errors block execution entirely, missing libraries only cause failures later in the make stage. Ensuring your environment is fully prepared before running the configure script saves significant debugging time.
Frequently Asked Questions
Why do I get "Permission denied" even after chmod?
If chmod fails or doesn't work, check if the filesystem is mounted as read-only or with the noexec flag. Additionally, verify that you are the owner of the file; if it belongs to root, you must use sudo chmod to modify its permissions.
What is the difference between ./configure and configure?
Using ./configure tells the shell to execute the script located in the current directory. Using just configure makes the shell search the directories listed in your PATH environment variable, which usually does not include the current folder, resulting in a "command not found" error.
Can I run configure without making the file executable?
Yes, you can run it through the shell explicitly by typing sh ./configure or bash ./configure. This bypasses the need for the execute bit on the script itself because you are passing the file as an argument to an already-running executable shell.
How do I fix permission errors on NFS mounts?
You need to remount the NFS share with the exec option allowed, or move your source code to a local filesystem. Contact your system administrator if you do not have the privileges to change mount options, as this is a server-side configuration.
Does SELinux affect standard Unix permissions?
Yes, SELinux acts as an additional mandatory access control layer. Even if chmod allows execution, SELinux may deny it based on the file's security context. You can diagnose this by checking audit logs or using getenforce to see if SELinux is enforcing policies.