简体   繁体   English

gradlew 错误:/usr/bin/env: bash: No such file or directory

[英]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-getyum安装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

Follow Arrow then ok , it works in @macOS #BigSur按照箭头然后确定,它适用于@macOS #BigSur 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 /usr/bin/bash: 没有这样的文件或目录 - /usr/bin/bash: No such file or directory 无法在 linux 中运行文件,/usr/bin/env: node: No such file or directory - cannot run a file in linux, /usr/bin/env: node: No such file or directory 我遇到了在服务器上找不到 npm 和节点的错误。 /usr/bin/env: node: 没有这样的文件或目录 - I encountered an error that could not find the npm and node on the server. /usr/bin/env: node: No such file or directory “#?/usr/bin/env bash”和“#!/usr/bin/bash”有什么区别? - What is the difference between "#!/usr/bin/env bash" and "#!/usr/bin/bash"? / usr / bin / env:python3.3:chroot中没有这样的文件或目录 - /usr/bin/env: python3.3: No such file or directory inside chroot RabbitMQ应用程序安装-/ usr / bin / env:escript:无此类文件或目录 - RabbitMQ app install - /usr/bin/env: escript: No such file or directory -bash: /usr/bin/yum: /usr/bin/python: bad interpreter: 没有那个文件或目录 - -bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory -bash: /usr/bin/virtualenvwrapper.sh: 没有那个文件或目录 - -bash: /usr/bin/virtualenvwrapper.sh: No such file or directory Python / usr / bin / env:错误的解释器:不是目录 - Python /usr/bin/env: bad interpreter: Not a directory /usr/bin/jekyll: 没有那个文件或目录 - /usr/bin/jekyll: No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM