Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

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

This comment has been minimized.

Copy link

beaujackson commented Sep 15, 2014

Nice. Thanks for the post.

@saul-mtz

This comment has been minimized.

Copy link

saul-mtz commented Sep 27, 2014

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

@nonus25

This comment has been minimized.

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

This comment has been minimized.

Copy link

alexmc6 commented Nov 11, 2014

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

@azbarcea

This comment has been minimized.

Copy link

azbarcea commented Jan 28, 2015

Nice. Thanks for the post.

@kalyankix

This comment has been minimized.

Copy link

kalyankix commented Apr 7, 2015

Thanks for the post.

@shyshkov

This comment has been minimized.

Copy link

shyshkov commented Apr 27, 2015

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

cesarjorgemartinez commented Sep 9, 2015

With Homebrew: brew install gradle

@parzonka

This comment has been minimized.

Copy link
Owner Author

parzonka commented Dec 3, 2015

Updated url and version to v2.9

@tuxtlacob

This comment has been minimized.

Copy link

tuxtlacob commented Dec 10, 2015

thanks!

@hamidnazari

This comment has been minimized.

Copy link

hamidnazari commented Mar 1, 2016

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
@fluffybastard

This comment has been minimized.

Copy link

fluffybastard 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

This comment has been minimized.

Copy link

johnpoth commented Mar 23, 2016

Above script works on Fedora 23 👍

@ablyeom

This comment has been minimized.

Copy link

ablyeom commented Mar 29, 2016

Yes, it works! Thx :)

@bowen-medallia

This comment has been minimized.

Copy link

bowen-medallia commented Apr 16, 2016

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

This comment has been minimized.

Copy link

pzbitskiy commented May 30, 2016

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

AndrewKralovec commented Sep 13, 2016

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

This comment has been minimized.

Copy link

robinkanters commented Sep 22, 2016

@AndrewKralovec

Try this:

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

This comment has been minimized.

Copy link

ravikondu commented May 24, 2018

Thanks! It was very succinct info.

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

@ejoful

This comment has been minimized.

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
You can’t perform that action at this time.