Gradlew causes 158 error on Ubuntu Linux

I try to run gradlew on my Umbutu Linux server using the command
sudo sh gradlew tasks
I get the following error:
gradlew: 158: gradlew: Syntax error: "(" unexpected

Gradle Version: 3.0
Operating System: Umbutu Linux 14.04.4
Is this a regression? No If yes, which version of Gradle do you know it last worked for?

First of all, it’s “Ubuntu”, not “Umbuntu”.

Can you try doing “sudo ./gradlew tasks”? The gradlew script is typically a Bash script, and I’m not sure what it would do if run from Bourne shell (I couldn’t get this error in my own testing).

I assume you have a specific reason for sudoing that.

Hi Andrew,

I think the main problem would be that on Ubuntu, by default, the root shell is Dash - which is not Bash compliant. Our gradlew shell script does not yet support that. There is an open pull request to add support, but it has been stalled for some time.

To fix your problem it would probably be enough to run

sudo bash gradlew tasks

Does this fix this for you?


Yes Stefan, That worked.