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?

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

1.  Create a script.  Call it 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.

curl -L$ > /tmp/gradle-$
mkdir /opt/gradle
unzip -d /opt/gradle /tmp/gradle-$
echo 'PATH="$PATH":/opt/gradle/gradle-'$version'/bin' > /etc/profile.d/
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/

Leave a comment

Your email address will not be published. Required fields are marked *