Installing Gradle
Gradlicious!
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’.
- Extract the Gradle archive to your Desktop. Remember the name of the directory that is extracted from the archive, you will need it later
- Open the Terminal application from the Utilities directory
- Type
sudo mkdir /Applications/gradle
and hit enter - Type
cd /Applications/gradle
and hit enter - Type
sudo cp -r ~/Desktop/name-of-gradle-directory .
and hit enter - Type
sudo ln -s name-of-gradle-directory target
and hit enter - Type
sudo ln -s /Applications/gradle/target/bin /usr/local/bin/gradle
and hit enter - Quit and open a new Terminal. Type
gradle --version
to confirm it is working - 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’.
- Extract the Gradle archive to your Desktop. Remember the name of the directory that is extracted from the archive, you will need it later
- Open a new File Explorer window and open the C:\ drive
- Create a new directory named ‘gradle’ in C:\
- Copy the directory you extracted from step 1. into the new ‘gradle’ directory
- Open the Windows menu (the Start menu), and type ‘Command Prompt’
- Right click on ‘Command Prompt’ and select ‘Run as Administrator’
- Type
cd C:\gradle
into the Command Prompt and hit enter - Type
mklink /J target name-of-gradle-directory
- Open the Windows menu again, and type ‘System Environment Variables’. Open the resulting shortcut
- Click the ‘Environment Variables’ button
- Under the ‘System Variables’, edit the ‘Path’ variable
- Click the ‘New’ button, and add
C:\gradle\target\bin
- Click OK to save your changes
- Close the Command Prompt that we opened earlier, and open a new Command Prompt. Type
gradle --version
to confirm it is working - You can now delete both the Gradle archive and the Gradle directory that you extracted to your Desktop
Setup on Linux
- 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
- Open a new Terminal
- Type
sudo mkdir -p /opt/gradle
and hit enter - Type
cd /opt/gradle
and hit enter - Type
sudo cp -r ~/name-of-gradle-directory .
and hit enter - Type
sudo ln -s name-of-gradle-directory target
and hit enter - Type
sudo ln -s /opt/gradle/target/bin /usr/local/bin/gradle
and hit enter - Close and open a new Terminal. Type
gradle --version
to confirm it is working - 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.