[英]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:使用 Git 将我的项目的
gradlew
文件从我的 Windows 机器提交到远程存储库后,在我的 Linux 服务器上调用gradlew
失败并显示以下消息:
/usr/bin/env: bash: No such file or directory
/usr/bin/env: bash: 没有那个文件或目录
What happened?发生了什么?
The problem's cause was that Git on Windows converted the line endings of gradlew
from Unix style (LF) to Windows style (CRLF).问题的原因是 Windows 上的 Git 将
gradlew
的行尾从 Unix 风格(LF)转换为 Windows 风格(CRLF)。
You can turn off that automatic conversion using git config core.autocrlf false
.您可以使用
git config core.autocrlf false
关闭自动转换。
Setting the line endings of gradlew
back to Unix style fixed the problem.将
gradlew
的行尾设置回 Unix 风格解决了这个问题。 In Vim this is done using :set fileformat=unix
.在Vim 中,这是使用
:set fileformat=unix
。
This is because the gradlew file has Windows file-endings.这是因为 gradlew 文件具有 Windows 文件结尾。
You can install dos2unix
with apt-get
or yum
by running:您可以通过运行以下命令使用
apt-get
或yum
安装dos2unix
:
sudo apt-get install dos2unix
sudo yum install -y dos2unix
and then use dos2unix
to convert the line-endings然后使用
dos2unix
转换行尾
from CRLF
Windows CarriageReturn + LineFeed来自
CRLF
Windows CarriageReturn + LineFeed
to LF
Linux LineFeed only:仅适用于
LF
Linux LineFeed:
dos2unix ./gradlew
Then run your gradlew
for a test:然后运行你的
gradlew
进行测试:
./gradlew clean -d
Thanks for the answers, these highlighted that the problem was Windows creating the gradlew, when I am on mac.感谢您的回答,这些强调了问题是 Windows 创建了 gradlew,当我在 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!这会创建(替换损坏的)一个 gradle 包装器,它有效! (notice it uses your local
gradle
install to fix the wrapper of the app) (注意它使用您本地的
gradle
安装来修复应用程序的包装器)
To solve it permanently for Git checkouts on Linux and Mac :要在 Linux 和 Mac 上永久解决Git 结账问题,请执行以下操作:
In your root Git repo directory add a file named .gitattributes
with this content:在您的根 Git 存储库目录中,添加一个名为
.gitattributes
的文件, .gitattributes
包含以下内容:
gradlew text eol=lf
More information: https://git-scm.com/docs/gitattributes更多信息: https : //git-scm.com/docs/gitattributes
PS: Works too for .sh
files using this entry: PS:也适用于使用此条目的
.sh
文件:
*.sh text eol=lf
The entries work at checkout time and convert the line endings of these files to LF
.这些条目在结帐时起作用并将这些文件的行尾转换为
LF
。
A vendor had shipped a gradlew
with Windows carriage returns.一个供应商发布了一个带有 Windows 回车符的
gradlew
。 Opening gradlew
in vim revealed ^M
line endings.在 vim 中打开
gradlew
显示^M
行结尾。 Running :e ++ff=dos
removed the line endings and resolved this issue.运行
:e ++ff=dos
删除了行尾并解决了这个问题。
As per https://vim.fandom.com/wiki/File_format根据https://vim.fandom.com/wiki/File_format
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.