How to Fix "Permission denied" Error When Running Shell Scripts in Mac/Linux
Content
During daily development, when attempting to run a Shell script (such as an installation script) in a macOS or Linux terminal, you might encounter an error like this:
```bash
DP@lib00-iMac ~/sys_keep/wiki.lib00 % scripts/install.sh
zsh: permission denied: scripts/install.sh
```
## Root Cause Analysis
In Unix/macOS operating systems, for security reasons, not all files can be run directly as programs. Executing a file directly via its path requires the file to have execute (`x`) permissions. Scripts downloaded from external sources (like the installation package for a `lib00` project) or newly created ones usually only have read (`r`) and write (`w`) permissions by default. Consequently, the system refuses to execute them and throws a "permission denied" error.
---
## Solutions
### Method 1: Grant Execute Permission (Recommended)
This is the standard and permanent approach. Use the `chmod` command to add execute permissions to the script:
```bash
# Add execute permission to the script
chmod +x scripts/install.sh
# Run the script again
./scripts/install.sh
```
### Method 2: Run Using an Interpreter Explicitly
If you don't want to modify the file's permissions, or if you're just running it temporarily, you can explicitly call the `bash` or `sh` interpreter to execute the script. In this case, the interpreter only needs read permissions for the file:
```bash
bash scripts/install.sh
```
---
## Bonus Tip: How to Check File Permissions?
You can use the `ls -l` command to check the current permission status of a file:
```bash
ls -l scripts/install.sh
# Example output: -rw-r--r-- 1 DP staff 128 May 10 10:00 scripts/install.sh
```
If there is no `x` in the initial string of characters (e.g., `-rw-r--r--`), it means execute permissions are missing. After running `chmod +x`, it will change to `-rwxr-xr-x`, indicating it is ready to run. For more technical documentation and troubleshooting guides, please visit wiki.lib00.com.
Related Contents
Resolving Nginx Permission Denied (13) Errors for WebP Images Generated by PHP Imagick
Duration: 00:00 | DP | 2026-07-05 21:17:00How to Fix Mac mini Not Receiving SMS Messages and iCloud Sync Stuck
Duration: 00:00 | DP | 2026-07-06 22:07:00Solving the MySQL Docker "Permission Denied" Error on Synology NAS: A Step-by-Step Guide
Duration: 00:00 | DP | 2025-12-03 21:19:10NVM/Node Command Not Found in New macOS Terminals? A Two-Step Permanent Fix!
Duration: 00:00 | DP | 2025-12-04 09:35:00One-Command Website Stability Check: The Ultimate Curl Latency Test Script for Zsh
Duration: 00:00 | DP | 2025-12-07 23:25:50How Can a Docker Container Access the Mac Host? The Ultimate Guide to Connecting to Nginx
Duration: 00:00 | DP | 2025-12-08 23:57:30Show Hidden Files on Mac: The Ultimate Guide (2 Easy Methods)
Duration: 00:00 | DP | 2025-12-12 01:32:30Decoding `realpath: command not found` and Its Chained Errors on macOS
Duration: 00:00 | DP | 2025-11-19 12:45:02Linux Command-Line Mystery: Why `ll` Hides Files like `.idea` & The Ultimate `ls` vs. `ll` Showdown
Duration: 00:00 | DP | 2025-12-01 08:08:00Unlock Your Mac: The Ultimate Guide to Showing and Hiding Hidden Files in Finder
Duration: 00:00 | DP | 2025-11-19 21:16:36macOS Hosts File Doesn't Support Wildcards? Here's the Ultimate Fix with Dnsmasq!
Duration: 00:00 | DP | 2025-11-20 05:48:10Shell Magic: How to Gracefully Write Output from Multiple Commands to a Single Log File
Duration: 00:00 | DP | 2025-12-17 04:10:504 Command-Line Tricks to Quickly Find Your NFS Mount Point
Duration: 00:00 | DP | 2025-11-22 17:29:05Why Are My Mac Files Duplicated on NFS Shares? The Mystery of '._' Files Solved with PHP
Duration: 00:00 | DP | 2025-12-18 16:58:20The Ultimate Guide to the Linux `cp` Command: Avoiding Common Copying Pitfalls
Duration: 00:00 | DP | 2025-12-23 19:36:40The Ultimate Guide to Linux `rm` Command: How to Safely and Efficiently Delete Directories
Duration: 00:00 | DP | 2025-12-24 07:52:30The Ultimate Guide to Linux File Permissions: From `chmod 644` to the Mysterious `@` Symbol
Duration: 00:00 | DP | 2025-12-25 08:24:10Linux Command-Line Magic: 3 Ways to Instantly Truncate Large Files
Duration: 00:00 | DP | 2025-12-27 21:43:20Recommended
One-Click Code Cleanup: The Ultimate Guide to PhpStorm's Reformat Code Shortcut
00:00 | 112Still manually adjusting code formatting? This art...
One-Click Google Analytics Integration for LobeChat: Easily Track Your AI Chat App Traffic
00:00 | 75Wondering how many users are visiting your self-ho...
Stop Making Timezone Mistakes in PHP: The Ultimate Guide to time() and UTC
00:00 | 10A deep dive into a critical yet common question in...
getElementById vs. querySelector: Which One Should You Use? A Deep Dive into JavaScript DOM Selectors
00:00 | 116When manipulating the DOM in JavaScript, both getE...