How Do You Install Gradle on Any Type of Linux?

Problem scenario
You want to be able to install Gradle on a Debian/Ubuntu Linux server, a Red Hat derivative of Linux (e.g., CentOS/RHEL/Fedora), or Linux SUSE.  How do you do this with the same script?

Prerequisites
i.  Install Java.  If you need directions, see this posting.
ii.  Install unzip. 

  • If you are using Debian or Ubuntu, run this command: sudo apt-get -y install unzip
  • If you are using a Red Hat deriviative (e.g., CentOS/RHEL/Fedora), run this command:  sudo yum -y install unzip
  • If you are using Linux SUSE, run this command:  sudo zypper -n install unzip

Procedures
1.  Create a script.  Call it gradle.sh and place it in the /tmp/ directory.  Here is the content:

# This script will work with any type of Linux.
# If you are using Debian/Ubuntu and have your repositories configured, it may be as simple as running:
# sudo apt -y install gradle  # But this script below allows you to change the version.

version=4.7
curl -L https://services.gradle.org/distributions/gradle-$version-bin.zip > /tmp/gradle-$version-bin.zip
mkdir /opt/gradle
unzip -d /opt/gradle /tmp/gradle-$version-bin.zip
echo 'PATH="$PATH":/opt/gradle/gradle-'$version'/bin' > /etc/profile.d/gradle.sh
echo "run this command below:"
echo "export PATH=$PATH:/opt/gradle/gradle-"$version"/bin "
echo "#to get Gradle to work"
echo "*** The installation script has finished. *** "
echo "to test the installation, run 'gradle -v'"

2.  Run it like this:  sudo bash /tmp/gradle.sh

Leave a comment

Your email address will not be published.