Matthias Braun
Matthias Braun

Reputation: 34383

Error with gradlew: /usr/bin/env: bash: No such file or directory

After committing my project's gradlew file from my Windows machine to the remote repo using Git, invoking gradlew on my Linux server failed with this message:

/usr/bin/env: bash: No such file or directory

What happened?

Upvotes: 59

Views: 66463

Answers (7)

humazed
humazed

Reputation: 76942

As mentioned in the other answers the problem is that Git on Windows converted the line endings of gradlew from Unix style (LF) to Windows style (CRLF).

the easier way to fix it is to run gradle wrapper from Android studio by following these steps:

1- Open the gradle panel and Click on Execute Gradle Task gradle panel

2- Type gradle wrapper Execute Gradle Task

3- Select gradle wrapper from the suggestions.

Upvotes: 1

Robert Halter
Robert Halter

Reputation: 382

To solve it permanently for Git checkouts on Linux and Mac:

In your root Git repo directory add a file named .gitattributes with this content:

gradlew text eol=lf

More information: https://git-scm.com/docs/gitattributes

PS: Works too for .sh files using this entry:

*.sh text eol=lf

The entries work at checkout time and convert the line endings of these files to LF.

Upvotes: 2

krishnendra
krishnendra

Reputation: 693

Follow Arrow then ok , it works in @macOS #BigSurenter image description here

Upvotes: 0

auzwang
auzwang

Reputation: 66

A vendor had shipped a gradlew with Windows carriage returns. Opening gradlew in vim revealed ^M line endings. Running :e ++ff=dos removed the line endings and resolved this issue.

As per https://vim.fandom.com/wiki/File_format

Upvotes: 1

Matthias Braun
Matthias Braun

Reputation: 34383

The problem's cause was that Git on Windows converted the line endings of gradlew from Unix style (LF) to Windows style (CRLF).

You can turn off that automatic conversion using git config core.autocrlf false.

Setting the line endings of gradlew back to Unix style fixed the problem. In Vim this is done using :set fileformat=unix.

Upvotes: 109

Blundell
Blundell

Reputation: 76546

Thanks for the answers, these highlighted that the problem was Windows creating the gradlew, when I am on mac.

To fix this, from the directory of the app I ran the command:

gradle wrapper

This creates (replaces the broken) a gradle wrapper, that works! (notice it uses your local gradle install to fix the wrapper of the app)

Upvotes: 15

Justin Rhoades
Justin Rhoades

Reputation: 711

This is because the gradlew file has Windows file-endings.

You can install dos2unix with apt-get or yum by running:

sudo apt-get install dos2unix

sudo yum install -y dos2unix

and then use dos2unix to convert the line-endings

from CRLF Windows CarriageReturn + LineFeed

to LF Linux LineFeed only:

dos2unix ./gradlew

Then run your gradlew for a test:

./gradlew clean -d

Upvotes: 69

Related Questions