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
macOS RAM Disk Deep Dive: Is Memory Allocation Dynamic or Fixed?
Duration: 00:00 | DP | 2026-07-09 20:02:36Declutter Your Desktop: How to Change macOS Screenshot Save Location via Command Line
Duration: 00:00 | DP | 2026-07-10 08:05:12macOS Advanced Guide: How to Elegantly Set Programs to Run at Startup
Duration: 00:00 | DP | 2026-07-07 09:20:15Resolving Nginx Permission Denied (13) Errors for WebP Images Generated by PHP Imagick
Duration: 00:00 | DP | 2026-07-05 21:17:00Boost Mac Productivity: How to Set F1-F12 as Standard Function Keys on macOS
Duration: 00:00 | DP | 2026-07-12 08:15:37Mac Tips: How to Display Seconds on the macOS Menu Bar Clock?
Duration: 00:00 | DP | 2026-07-12 20:18:13Bypassing macOS Restrictions: How to Set a 1-Digit Login Password
Duration: 00:00 | DP | 2026-07-13 08:20:49How to Fix Mac mini Not Receiving SMS Messages and iCloud Sync Stuck
Duration: 00:00 | DP | 2026-07-06 22:07:00How to Prevent Apple Compressor from Replacing Dots with Underscores in Filenames
Duration: 00:00 | DP | 2026-07-17 20:44:15Stop Using rm! 5 Pro Ways to Quickly Clear Log Files in Linux
Duration: 00:00 | DP | 2026-07-18 20:49:27Never Lose Output Again: How to Show Unlimited Scrollback History in macOS iTerm2
Duration: 00:00 | DP | 2026-07-21 21:05:04DevOps Practice: How to Safely Clear Logs of a Running Docker Container?
Duration: 00:00 | DP | 2026-07-27 09:33:42Say Goodbye to Line-by-Line Deletion: A Guide to Efficiently Bulk Editing and Cleaning Crontab on Linux
Duration: 00:00 | DP | 2026-07-30 09:49:20Cron Job Failing? The Ultimate Guide to Fixing 'docker: command not found'
Duration: 00:00 | DP | 2026-08-01 09:59:44Solving 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:30Recommended
Streamline Your Yii2 Console: How to Hide Core Commands and Display Only Your Own
00:00 | 125Tired of scrolling through a long list of core fra...
Master cURL Timeouts: A Definitive Guide to Fixing "Operation timed out" Errors
00:00 | 218Frequently encountering "cURL Error: Operation tim...
The Ultimate Vue SPA SEO Guide: Perfect Indexing with Nginx + Static Generation
00:00 | 239Struggling with SEO for your Vue Single Page Appli...
Step-by-Step Guide to Fixing `net::ERR_SSL_PROTOCOL_ERROR` in Chrome for Local Nginx HTTPS Setup
00:00 | 277Struggling with the `net::ERR_SSL_PROTOCOL_ERROR` ...