Software⏱️ 4 min read📅 2026-06-03

How to Fix: gradlew: Permission Denied

Gradle permission denied error resolved by running gradlew with sudo.

Quick Answer: Run gradlew with sudo to resolve the permission denied error, e.g., sudo ./gradlew compileDebug --stacktrace

The 'Permission Denied' error when attempting to run gradlew from the command line is a common issue that affects various users, including developers and IT professionals. This error occurs when the system does not grant the necessary permissions for the user to execute the gradlew script.

This frustration-inducing error can be caused by a variety of factors, including incorrect file ownership or permissions, conflicting system settings, or insufficient privileges.

🛑 Root Causes of the Error

  • The primary cause of this error is typically related to file ownership and permissions. When the user attempting to run gradlew does not have the necessary permissions to execute the script, the system returns a 'Permission Denied' error.
  • Another possible cause could be related to conflicting system settings or configuration issues. This may include incorrect file permissions, a misconfigured environment variable, or an outdated version of the operating system.

✅ Best Solutions to Fix It

Change File Ownership and Permissions

  1. Step 1: Step 1: Open the Terminal application on your MacBook Pro.
  2. Step 2: Step 2: Navigate to the project directory where you are trying to run gradlew using the 'cd' command. For example, if your project is named 'appx_android', use the command 'cd appx_android'.
  3. Step 3: Step 3: Use the 'ls -l' command to check the current file ownership and permissions of the gradlew script. This will display information about the file's owner, group, and permissions.
  4. Step 4: Step 4: Identify the user who owns the gradlew script (usually the system user or root user) and determine their permission level. Typically, this is a 'root' user with full privileges.
  5. Step 5: Step 5: Use the 'sudo' command to change the ownership of the gradlew script to the current user's account. This can be done by adding the '-u' option followed by the username (e.g., 'sudo chown -u brendalogy gradlew').
  6. Step 6: Step 6: Change the file permissions using the 'chmod' command. For example, you can change the permissions to '755' for read, write, and execute access. This may require using the '-R' option to recursively apply the changes to all files in the directory.
  7. Step 7: Step 7: Verify that the ownership and permissions have been successfully changed by running the 'ls -l' command again.

Run gradlew with Elevated Privileges

  1. Step 1: Step 1: Open the Terminal application on your MacBook Pro.
  2. Step 2: Step 2: Navigate to the project directory where you are trying to run gradlew using the 'cd' command. For example, if your project is named 'appx_android', use the command 'cd appx_android'.
  3. Step 3: Step 3: Use the 'sudo' command to run gradlew with elevated privileges. This will execute the script as the root user, bypassing permission restrictions.
  4. Step 4: Step 4: Verify that the 'Permission Denied' error has been resolved by running the './gradlew compileDebug --stacktrace' command again.

✨ Wrapping Up

To resolve the 'Permission Denied' error when attempting to run gradlew from the command line, you can try changing file ownership and permissions or running the script with elevated privileges. By following these steps, you should be able to successfully execute the gradlew script and avoid this frustrating error.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions