Image source: Gradle Inc. / crazyadmins.com

Installing Gradle

Gradlicious!

Published in
3 min readJan 26, 2017

--

Gradle is a fantastic build automation tool, capable of building everything from Java to iOS applications.

Installing Gradle can be intimidating if you are not familiar with the command line. In this post, I will outline how to install it on several platforms.

Note: This guide is not the final word on how to install Gradle. Some aspects can be changed to your liking.

Step 1. Download Gradle

Via a web browser

You can download Gradle from here. You will want the binary release, unless you want the source code and example code too. Gradle is platform agnostic; there are no operating specific downloads.

Via the command line

Run curl -O https://services.gradle.org/distributions/gradle-3.3-bin.zip

Step 2. Install the Java Development Kit (JDK)

Download the JDK for your operating system. Installing JDK is usually very straight forward:

  • For Windows and macOS, simply run the installer
  • For RedHat based Linux systems, install the .rpm
  • For other Linux operating systems, checkout Salem’s post.

Step 3. Setup Gradle

While Gradle is platform agnostic, you still need to do some platform-specific configuration. See below for instructions specific to your operating system.

Setup on macOS

Note: When I say ‘directory’, I am referring to a standard macOS ‘folder’.

  1. Extract the Gradle archive to your Desktop. Remember the name of the directory that is extracted from the archive, you will need it later
  2. Open the Terminal application from the Utilities directory
  3. Type sudo mkdir /Applications/gradle and hit enter
  4. Type cd /Applications/gradle and hit enter
  5. Type sudo cp -r ~/Desktop/name-of-gradle-directory . and hit enter
  6. Type sudo ln -s name-of-gradle-directory target and hit enter
  7. Type sudo ln -s /Applications/gradle/target/bin /usr/local/bin/gradle and hit enter
  8. Quit and open a new Terminal. Type gradle --version to confirm it is working
  9. You can now delete both the Gradle archive and the Gradle directory that you extracted to your Desktop

Setup on Windows

Note: When I say ‘directory’, I am referring to a standard Windows ‘folder’.

  1. Extract the Gradle archive to your Desktop. Remember the name of the directory that is extracted from the archive, you will need it later
  2. Open a new File Explorer window and open the C:\ drive
  3. Create a new directory named ‘gradle’ in C:\
  4. Copy the directory you extracted from step 1. into the new ‘gradle’ directory
  5. Open the Windows menu (the Start menu), and type ‘Command Prompt’
  6. Right click on ‘Command Prompt’ and select ‘Run as Administrator’
  7. Type cd C:\gradle into the Command Prompt and hit enter
  8. Type mklink /J target name-of-gradle-directory
  9. Open the Windows menu again, and type ‘System Environment Variables’. Open the resulting shortcut
  10. Click the ‘Environment Variables’ button
  11. Under the ‘System Variables’, edit the ‘Path’ variable
  12. Click the ‘New’ button, and add C:\gradle\target\bin
  13. Click OK to save your changes
  14. Close the Command Prompt that we opened earlier, and open a new Command Prompt. Type gradle --version to confirm it is working
  15. You can now delete both the Gradle archive and the Gradle directory that you extracted to your Desktop

Setup on Linux

  1. Extract the Gradle archive to your home directory. Remember the name of the directory that is extracted from the archive, you will need it later
  2. Open a new Terminal
  3. Type sudo mkdir -p /opt/gradle and hit enter
  4. Type cd /opt/gradle and hit enter
  5. Type sudo cp -r ~/name-of-gradle-directory . and hit enter
  6. Type sudo ln -s name-of-gradle-directory target and hit enter
  7. Type sudo ln -s /opt/gradle/target/bin /usr/local/bin/gradle and hit enter
  8. Close and open a new Terminal. Type gradle --version to confirm it is working
  9. You can now delete both the Gradle archive and the Gradle directory that you extracted to your home directory

Troubleshooting

‘Cannot find JAVA_HOME’ or ‘JAVA_HOME is not set’

Make sure that you have installed Oracle’s Java Development Kit. After doing that, follow these instructions to set the JAVA_HOME variable.

‘Permission denied’ or similar permissions related errors

On macOS or Linux, make sure that you are using sudo to copy Gradle installation files around. If you are on Windows, make sure you are running the Command Prompt as an Administrator when creating symlinks.

--

--