如何将 Gradle 升级到 6.7.1

如何将 Gradle 升级到 6.7.1

我需要使用 gradle 6.7 并遵循这个建议尝试升级:

sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt upgrade gradle

其中包括注销:

Get:1 http://ppa.launchpad.net/cwchien/gradle/ubuntu focal/main amd64 gradle all 6.7.1-0ubuntu1 [3.432 B]
Fetched 3.432 B in 0s (13,2 kB/s)  
Selecting previously unselected package gradle.
(Reading database ... 285000 files and directories currently installed.)
Preparing to unpack .../gradle_6.7.1-0ubuntu1_all.deb ...
Unpacking gradle (6.7.1-0ubuntu1) ...
Setting up gradle (6.7.1-0ubuntu1) ...

哦,太好了,我想,它安装了 gradle 6.7.1!但不幸的是什么都没有改变:

gradle --version

------------------------------------------------------------
Gradle 6.6.1
------------------------------------------------------------

Build time:   2020-08-25 16:29:12 UTC
Revision:     f2d1fb54a951d8b11d25748e4711bec8d128d7e3

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          1.8.0_275 (Private Build 25.275-b01)
OS:           Linux 5.4.0-60-generic amd64

which gradle指向/usr/bin/gradle的是符号链接

/usr/bin/gradle -> /etc/alternatives/gradle

答案1

在 /tmp 目录中下载最新版本的 gradle (https://gradle.org/releases/

cd /tmp

获得https://services.gradle.org/distributions/gradle-7.3.3-bin.zip

解压下载的文件

sudo unzip -d /opt/gradle /tmp/gradle-7.3.3-bin.zip

sudo ln -s /opt/gradle/gradle-7.3.3 /opt/gradle/latest

设置环境变量

sudo nano /etc/profile.d/gradle.sh

#添加下面两行:

导出 GRADLE_HOME=/opt/gradle/latest

导出 PATH=${GRADLE_HOME}/bin:${PATH}

使上面创建的脚本可执行: sudo chmod +x /etc/profile.d/gradle.sh

加载环境变量: 源 /etc/profile.d/gradle.sh

验证 gradle 安装

gradle-v 复制代码

输出:欢迎使用 Gradle 7.3.3!

请点击以下链接获取详细说明:

https://linuxize.com/post/how-to-install-gradle-on-ubuntu-20-04/

相关内容