How do I upgrade Gradle?

88,291

Solution 1

You could use the ppa for the almost-always latest version

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

or SDKMAN for the latest version

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install gradle

Advantages of the ppa

  • auto-updates with the system
  • no piping of downloaded scripts to the shell

Advantages of sdkman: latest version supplied by gradle themselves.

Solution 2

You can also tell Gradle to update itself using a Gradle wrapper.

First you create the wrapper, then tell it to use the Gradle version of your choice:

gradle wrapper
./gradlew wrapper --gradle-version 4.9

Now this project will use Gradle 4.9, independent of what's installed. However, you need to remember to run Gradle through the wrapper, i.e., run ./gradlew instead of plain gradle.

The wrapper allows you to have different projects using different Gradle versions easily.

When you commit the created wrapper to source control, everybody who checks out the project will use the same Gradle version. This can help a lot with incompatible build scripts, when something has changed between Gradle versions.

Solution 3

download from https://gradle.org/releases/

pick the binary-only link as per

v4.10.3

Dec 05, 2018

Download: binary-only or complete

after you expand the download just update your PATH env var to pickup this new binary

vi ~/.bashrc  # or where ever your shell's env vars are defined

and add following line to bottom of ~/.bashrc

#   replace ~/src/gradle-4.10.3/bin with your location
export PATH=~/src/gradle-4.10.3/bin:$PATH

confirm this works by issuing

source ~/.bashrc
gradle --version
Share:
88,291
Alexey Ce
Author by

Alexey Ce

Updated on September 18, 2022

Comments

  • Alexey Ce
    Alexey Ce over 1 year

    This shows that Gradle is up to date:

    thufir@doge:~$ sudo apt install gradle
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    gradle is already the newest version (2.10-1).
    0 upgraded, 0 newly installed, 0 to remove and 629 not upgraded.
    

    How do I upgrade to Gradle 4.x? Preferably, with umake rather than SDKMAN! which seems to be what they suggest.

    (I don't want to update all the packages due to a slow connection.)

  • Anum Sheraz
    Anum Sheraz almost 6 years
    I got error while running upgrade gradle as The following packages have unmet dependencies. powershell : Depends: liblttng-ust0 but it is not installed . I have to run this sudo apt-get -f install then sudo apt-get -f install gradle. This way, it deletes the previous one and installs the latest from scratch.
  • serv-inc
    serv-inc almost 6 years
    @AnumSheraz: powershell is in another repository altogether. It should not have anything to do with gradle. But it seems like sudo apt-get -f install fixed its problem.
  • kodmanyagha
    kodmanyagha over 5 years
    you're lifesaver. My gradle version was 2 and throws that exception: gradle failed to apply plugin id 'com.google.protobuf' After update gradle the problem is gone. Thanks.
  • naXa stands with Ukraine
    naXa stands with Ukraine about 5 years
    This PPA does not serve up-to-date Gradle. Now my Gradle version is 5.2 (installed via apt) while there's 5.3.1 available for download from the official website.
  • serv-inc
    serv-inc about 5 years
    @naXa: if you really need the very latest, see the update. You will miss out on automatic updates.
  • serv-inc
    serv-inc about 5 years
    @naXa: the ppa has been updated to 5.3.1
  • Michael_H
    Michael_H over 4 years
    I had to remove the installed version with sudo apt remove gradle and then install the new version with the ppa to update to the newest version.
  • Csaba Toth
    Csaba Toth over 2 years
    I cannot generate the wrapper because the system gradle is too old