Skip to content

Instantly share code, notes, and snippets.

@parzonka
Last active July 4, 2024 05:28
Show Gist options
  • Save parzonka/9371885 to your computer and use it in GitHub Desktop.
Save parzonka/9371885 to your computer and use it in GitHub Desktop.
Install gradle on redhat/centos linux
# installs to /opt/gradle
# existing versions are not overwritten/deleted
# seamless upgrades/downgrades
# $GRADLE_HOME points to latest *installed* (not released)
gradle_version=2.9
wget -N https://services.gradle.org/distributions/gradle-${gradle_version}-all.zip
sudo unzip -foq gradle-${gradle_version}-all.zip -d /opt/gradle
sudo ln -sfn gradle-${gradle_version} /opt/gradle/latest
sudo printf "export GRADLE_HOME=/opt/gradle/latest\nexport PATH=\$PATH:\$GRADLE_HOME/bin" > /etc/profile.d/gradle.sh
. /etc/profile.d/gradle.sh
# check installation
gradle -v
@arupray
Copy link

arupray commented Jun 26, 2014

Thank you. I had to create /opt/gradle myself. The unzip -d did not do it for me. Also before checking gradle -v, I had to make sure that JAVA_HOME was set. Thanks for a very concise writeup.

@beaujackson
Copy link

Nice. Thanks for the post.

@saul-mtz
Copy link

Thanks for share it, is works perfectly for gradle 1.5, you should change the download URL for http://downloads.gradle.org/distributions

@nonus25
Copy link

nonus25 commented Oct 8, 2014

I had some troubles when was trying run yours script so i did small changes to fix this.

#!/bin/bash
# installs to /opt/gradle
# existing versions are not overwritten/deleted
# seamless upgrades/downgrades
# $GRADLE_HOME points to latest *installed* (not released)
gradle_version=1.11
mkdir /opt/gradle
wget -N http://services.gradle.org/distributions/gradle-${gradle_version}-all.zip
unzip -oq ./gradle-${gradle_version}-all.zip -d /opt/gradle
ln -sfnv gradle-${gradle_version} /opt/gradle/latest
printf "export GRADLE_HOME=/opt/gradle/latest\nexport PATH=\$PATH:\$GRADLE_HOME/bin" > /etc/profile.d/gradle.sh
. /etc/profile.d/gradle.sh
rehash ; sync
# check installation
gradle -v

@alexmc6
Copy link

alexmc6 commented Nov 11, 2014

Cheers. I had to manually create /opt/gradle and run the commands by hand, but thanks.

@azbarcea
Copy link

Nice. Thanks for the post.

@kalyankix
Copy link

Thanks for the post.

@shyshkov
Copy link

With a few changes works great on RHEL 7.1. Thank you!

#!/bin/bash
# installs to /opt/gradle
# existing versions are not overwritten/deleted
# seamless upgrades/downgrades
# $GRADLE_HOME points to latest *installed* (not released)
gradle_version=2.3
mkdir /opt/gradle
wget -N http://services.gradle.org/distributions/gradle-${gradle_version}-all.zip
unzip -oq ./gradle-${gradle_version}-all.zip -d /opt/gradle
ln -sfnv gradle-${gradle_version} /opt/gradle/latest
printf "export GRADLE_HOME=/opt/gradle/latest\nexport PATH=\$PATH:\$GRADLE_HOME/bin" > /etc/profile.d/gradle.sh
. /etc/profile.d/gradle.sh
hash -r ; sync
# check installation
gradle -v

@croucha
Copy link

croucha commented Jun 5, 2015

Download address has changed...

#!/bin/bash
# installs to /opt/gradle
# existing versions are not overwritten/deleted
# seamless upgrades/downgrades
# $GRADLE_HOME points to latest *installed* (not released)
gradle_version=2.3
mkdir /opt/gradle
wget -N http://downloads.gradle.org/distributions/gradle-${gradle_version}-all.zip
unzip -oq ./gradle-${gradle_version}-all.zip -d /opt/gradle
ln -sfnv gradle-${gradle_version} /opt/gradle/latest
printf "export GRADLE_HOME=/opt/gradle/latest\nexport PATH=\$PATH:\$GRADLE_HOME/bin" > /etc/profile.d/gradle.sh
. /etc/profile.d/gradle.sh
hash -r ; sync
# check installation
gradle -v

@cesarjorgemartinez
Copy link

With Homebrew: brew install gradle

@parzonka
Copy link
Author

parzonka commented Dec 3, 2015

Updated url and version to v2.9

@tuxtlacob
Copy link

thanks!

@hamidnazari
Copy link

Thanks for this. Small improvement though:

sudo printf "export GRADLE_HOME=/opt/gradle/latest\nexport PATH=\$PATH:\$GRADLE_HOME/bin" > /etc/profile.d/gradle.sh

should be

printf "export GRADLE_HOME=/opt/gradle/latest\nexport PATH=\$PATH:\$GRADLE_HOME/bin" | sudo tee /etc/profile.d/gradle.sh >/dev/null

Copy link

ghost commented Mar 8, 2016

Building on what others wrote, here is a small script that works on Centos 7 (always returns the latest version of gradle from the URL)

#!/bin/bash
cd /root
gradle_package=`curl -s http://services.gradle.org/distributions --list-only | sed -n 's/.*\(gradle-.*.all.zip\).*/\1/p' | egrep -v "milestone|rc" | head -1`
gradle_version=`ls ${gradle_package} | cut -d "-" -f 1,2`
mkdir /opt/gradle
wget -N http://services.gradle.org/distributions/${gradle_package}
unzip -oq ./${gradle_package} -d /opt/gradle
ln -sfnv ${gradle_version} /opt/gradle/latest
printf "export GRADLE_HOME=/opt/gradle/latest\nexport PATH=\$PATH:\$GRADLE_HOME/bin" > /etc/profile.d/gradle.sh
. /etc/profile.d/gradle.sh
hash -r ; sync
# check installation
gradle -v

@johnpoth
Copy link

Above script works on Fedora 23 👍

@ablyeom
Copy link

ablyeom commented Mar 29, 2016

Yes, it works! Thx :)

@bowen-medallia
Copy link

If you don't have wget installed and want to stick with curl for the download as well, replace the wget line with:

curl -L -Of http://services.gradle.org/distributions/${gradle_package}

@pzbitskiy
Copy link

Fixed gradle_version determination in @fluffybastard version. Checked on CentOS 7.1

#!/bin/bash
cd /root
gradle_package=`curl -s http://services.gradle.org/distributions --list-only | sed -n 's/.*\(gradle-.*.all.zip\).*/\1/p' | egrep -v "milestone|rc" | head -1`
gradle_version=`echo ${gradle_package} | cut -d "-" -f 1,2`
mkdir /opt/gradle
curl -L -Of http://services.gradle.org/distributions/${gradle_package}
unzip -oq ./${gradle_package} -d /opt/gradle
ln -sfnv ${gradle_version} /opt/gradle/latest
printf "export GRADLE_HOME=/opt/gradle/latest\nexport PATH=\$PATH:\$GRADLE_HOME/bin" > /etc/profile.d/gradle.sh
. /etc/profile.d/gradle.sh
hash -r ; sync
# check installation
gradle -v

@VGerris
Copy link

VGerris commented Aug 26, 2016

It became easy :
https://gradle.org/gradle-download/
Snippet:
Install with SDKMAN!

Get SDKMAN!
$ curl -s https://get.sdkman.io | bash

Open a new terminal and install Gradle
$ sdk install gradle 3.0

@AndrewKralovec
Copy link

sudo printf "export GRADLE_HOME=/opt/gradle/latest\nexport PATH=$PATH:$GRADLE_HOME/bin" > /etc/profile.d/gradle.sh

I get
-bash: /etc/profile.d/gradle.sh: Permission denied

But im the root user and im using the sudo command

@robinkanters
Copy link

@AndrewKralovec

Try this:

printf "export GRADLE_HOME=/opt/gradle/latest\nexport PATH=\$PATH:\$GRADLE_HOME/bin" | sudo tee /etc/profile.d/gradle.sh

@ravikondu
Copy link

Thanks! It was very succinct info.

Instead of gradle -v I had to do /opt/gradle/bin/gradle -v

@ejoful
Copy link

ejoful commented Jul 6, 2018

CentOS Linux release 7.5.1804 (Core)

# !/bin/bash
# installs to /opt/gradle
# existing versions are not overwritten/deleted
# seamless upgrades/downgrades
# $GRADLE_HOME points to latest *installed* (not released)
gradle_version=4.8.1
if [ ! -d "/opt/gradle" ];then
mkdir /opt/gradle
fi
if [ ! -f "./gradle-${gradle_version}-all.zip" ];then
wget -N http://services.gradle.org/distributions/gradle-${gradle_version}-all.zip
fi
unzip -oq ./gradle-${gradle_version}-all.zip -d /opt/gradle
ln -sfnv gradle-${gradle_version} /opt/gradle/latest
printf "export GRADLE_HOME=/opt/gradle/latest\nexport PATH=\$PATH:\$GRADLE_HOME/bin" > /etc/profile.d/gradle.sh
. /etc/profile.d/gradle.sh
hash -r ; sync
# check installation
gradle -v

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment