Gradle 是一个构建自动化工具,用于构建不同的应用程序,从移动应用程序到微服务。它非常灵活,可以帮助开发人员团队自动化和构建更轻松、更快速的软件。Gradle是用Java编程语言编写的,广泛用于基于Java的项目的开发,特别是那些使用Java开发人员工具包(JDK)的项目。
在 Ubuntu 22.04 LTS Jammy Jellyfish 上安装 Gradle
第 1 步。首先,通过在终端中运行以下命令,确保所有系统软件包都是最新的。apt
<span class="pln">sudo apt update sudo apt upgrade</span>
第 2 步。安装爪哇。
Gradle 依赖于 Java,所以首先,我们需要在服务器上安装 Java。现在运行以下命令来安装 Java:
<span class="pln">sudo apt install </span><span class="kwd">default</span><span class="pun">-</span><span class="pln">jdk</span>
我们将检查已安装的 Java 软件包的版本:
<span class="pln">java </span><span class="pun">--</span><span class="pln">version</span>
有关安装 Java 的其他资源,请阅读下面的帖子:
- 如何在 Ubuntu Linux √ 上安装 Java
第 3 步。在 Ubuntu 22.04 上安装 Gradle。
默认情况下,Gradle 在 Ubuntu 22.04 基本存储库中不可用。现在运行以下命令,从其官方页面下载最新的 Gradle 发行版二进制文件。到你的 Ubuntu 系统:
<span class="pln">wget https</span><span class="pun">:</span><span class="com">//services.gradle.org/distributions/gradle-7.6-bin.zip</span>
接下来,提取目录中的 zip 文件:/opt/gradle
<span class="pln">unzip </span><span class="pun">-</span><span class="pln">d </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">gradle </span><span class="pun">/</span><span class="pln">tmp</span><span class="pun">/</span><span class="pln">gradle</span><span class="pun">-</span><span class="lit">7.6</span><span class="pun">-</span><span class="pln">bin</span><span class="pun">.</span><span class="pln">zip</span>
之后,我们创建一个名为 的符号链接,该链接指向 Gradle 安装目录:latest
<span class="pln">sudo ln </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">gradle</span><span class="pun">/</span><span class="pln">gradle</span><span class="pun">-</span><span class="lit">7.6</span> <span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">gradle</span><span class="pun">/</span><span class="pln">latest</span>
第 4 步。设置环境变量。
现在要设置环境变量,我们将使用 nano 文本编辑器打开其 “” 文件:sh
<span class="pln">nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">profile</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">gradle</span><span class="pun">.</span><span class="pln">sh</span>
添加以下配置:
<span class="kwd">export</span><span class="pln"> PATH</span><span class="pun">=</span><span class="str">/opt/</span><span class="pln">gradle</span><span class="pun">/</span><span class="pln">gradle</span><span class="pun">-</span><span class="lit">7.6</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">:</span><span class="pln">$PATH</span>
保存并关闭文件,然后通过更改其访问权限使文件可执行:
<span class="pln">chmod </span><span class="pun">+</span><span class="pln">x </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">profile</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">gradle</span><span class="pun">.</span><span class="pln">sh</span>
现在源脚本以将环境应用于当前 shell:
<span class="pln">source </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">profile</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">gradle</span><span class="pun">.</span><span class="pln">sh</span>
为了确认安装Gradle,我们将检查其安装的版本:
<span class="pln">gradle </span><span class="pun">-</span><span class="pln">v</span>
输出:
<span class="typ">Welcome</span><span class="pln"> to </span><span class="typ">Gradle</span> <span class="lit">7.6</span><span class="pun">!</span>
感谢您使用本教程在 Ubuntu 22.04 LTS Jammy Jellyfish 系统上安装 Gradle。如需更多帮助或有用信息,我们建议您查看 Gradle 官方网站。