./gradlew will not run: permission denied
bash: ./gradlew: Permission deniedShort answer
The gradlew script has lost its executable bit, usually after a zip download, a Windows checkout or a copy to another disk. Run chmod +x gradlew locally. To fix it for everyone, record the bit in Git with git update-index --chmod=+x gradlew and commit.
Fix it fast
1Find out which cause you have
Check the permission string. If there is no x in it, this page applies.
ls -l gradlew2Match what you see, then jump to its fix
- 1
-rw-r--r-- on gradlewThe file has no executable bit on your machineFix - 2
Works on your Mac, fails in CI or on a fresh clone with the same messageGit stored the file as non-executable, so CI checks it out that wayFix - 3
gradlew is missing, or the next error is about gradle-wrapper.jarThe wrapper files were never committed togetherFix
- 1
What does the error look like?
bash: ./gradlew: Permission deniedzsh: permission denied: ./gradlew
Cause 1 of 3
The file has no executable bit on your machine
1Check
A zip download, an unzip from Windows or a copy to an exFAT or NTFS disk does not keep Unix permissions.
ls -l gradlew2Fix
Add the executable bit to the launcher script.
chmod +x gradlew3Verify
The Gradle version prints.
./gradlew --versionConfirmed by docs.gradle.org
Cause 2 of 3
Git stored the file as non-executable, so CI checks it out that way
1Check
The index mode for the file should be 100755. If it shows 100644, every clone gets a script that cannot run.
git ls-files --stage gradlew2Fix
Set the bit in the index and commit. Git's own documentation describes --chmod=(+|-)x for this.
git update-index --chmod=+x gradlew
git commit -m "Make gradlew executable"3Verify
The index now shows mode 100755.
git ls-files --stage gradlewConfirmed by git-scm.com
Cause 3 of 3
The wrapper files were never committed together
1Check
Gradle's documentation lists four files that belong in version control: gradlew, gradlew.bat, gradle-wrapper.jar and gradle-wrapper.properties.
git ls-files gradlew gradlew.bat gradle/wrapper2Fix
Regenerate the wrapper with an installed Gradle, then commit all four files.
gradle :wrapper
git add gradlew gradlew.bat gradle/wrapper3Verify
A fresh clone builds.
./gradlew --versionConfirmed by docs.gradle.org
How do I stop it coming back?
- Commit the executable bit once with git update-index --chmod=+x and never copy the project through a zip.
- In CI, call ./gradlew only after checkout, and keep a check that fails on mode 100644.
- Work on Linux-style filesystems for Gradle projects, not exFAT or NTFS.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Mobile apps
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain
The gradlew script starts Java with gradle/wrapper/gradle-wrapper.jar, and that JAR does not exist or is damaged.
2 causes, each with a fixMobile apps
The shell says gradlew: command not found
bash: gradlew: command not found
The shell cannot find a launcher called gradlew.
3 causes, each with a fixMobile apps
sdkmanager command not found after installing the Android SDK
bash: sdkmanager: command not found
sdkmanager lives in the Android Command-line Tools package, at cmdline-tools/latest/bin inside the SDK folder.
3 causes, each with a fixMobile apps
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fixMobile apps
adb prints 'server version doesn't match this client; killing...'
adb server version doesn't match this client; killing...
adb runs a background server, and every adb command is a client.
3 causes, each with a fix