Home » Java » Enterprise Java » How to Install Gradle

About Steve Hanson

Steve Hanson

Steve is a software developer interested in web development and new technologies. He currently works as a Java consultant at Credera in Dallas, TX.

How to Install Gradle

Gradle is a dependency management / build tool that combines the best of Maven and Ant, making it an extremely powerful and customizable tool. It also uses a sleek Groovy DSL instead of the XML approach of Maven and Ant and is my personal tool-of-choice when I start a new project. Here’s how to install. I’ll write a future post to get us started with some Gradle projects.

1. Install Java

First you need to have the Java JDK (Java Development Kit) installed; having the JRE (Java Runtime Environment) is not enough. To check if you have the JDK installed, open a command prompt or terminal and type javac -version. If you have a JDK
 
installed, you will see your javac version output, eg. javac 1.7.0_01. If you get an error that javac is not a recognized command, download and install the Java JDK.

2. Download Gradle

3. Unpack and Set System variables

Windows

  1. Unzip the Gradle download to the folder to which you would like to install Gradle, eg. “C:\Program Files”. The subdirectory gradle-x.x will be created from the archive, where x.x is the version.
  2. Add location of your Gradle “bin” folder to your path. Open the system properties (WinKey + Pause), select the “Advanced” tab, and the “Environment Variables” button, then add “C:\Program Files\gradle-x.x\bin” (or wherever you unzipped Gradle) to the end of your “Path” variable under System Properties. Be sure to omit any quotation marks around the path even if it contains spaces. Also make sure you separated from previous PATH entries with a semicolon “;”.
  3. In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:\Program Files\Java\jdk1.7.0_06 and that %JAVA_HOME%\bin is in your Path environment variable.
  4. Open a new command prompt (type cmd in Start menu) and run gradle –version to verify that it is correctly installed.

Mac/Linux

  1. Extract the distribution archive, i.e. gradle-x.x-bin.tar.gz to the directory you wish to install Gradle. These instructions assume you chose /usr/local/gradle. The subdirectory gradle-x.x will be created from the archive.
  2. In a command terminal, add Gradle to your PATH variable: export PATH=/usr/local/gradle/gradle-x.x/bin:$PATH
  3. Make sure that JAVA_HOME is set to the location of your JDK, e.g. export JAVA_HOME=/usr/java/jdk1.7.0_06 and that $JAVA_HOME/bin is in your PATH environment variable.
  4. Run gradle –version to verify that it is correctly installed.

You now have Gradle set up! Stay tuned for another post on how to build a simple Gradle project.

More reading:

 

Reference: How to Install Gradle from our JCG partner Steve Hanson at the CodeTutr blog.
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
Email address:

Leave a Reply

8 Comments on "How to Install Gradle"

Notify of
avatar
Sort by:   newest | oldest | most voted
Tibo Delor
Guest

And then, enable the wrapper so the others devs don’t have to install it ;)

Steve Hanson
Guest

Good point! I’ll write another post about the wrapper :)

Gibran Castillo
Guest

How do you enable the wrapper? Why do you need the gradle wrapper enable? What does it do?

Haikal Saadh
Guest

If you’re on Mac/linux, you can simply install GVM. It downloads, unpacks, and sets up your environment for you. (And makes it easier to change the version of grails/gradle you’re using, to boot) http://gvmtool.net/

hadis
Guest

tank you a lot !!!
:-*

Daniel Hankins
Guest
Those Linux instructions will work… right up to the moment you open another command terminal, or reboot the machine, or do anything that relies on the PATH variable outside that command window or any of its subprocesses. It would be better if the instructions told how to persist the PATH across boots, and warned that once done a reboot (or logout/login, depending on how you persisted PATH) is necessary for all command terminals and processes on the machine to pick up the change to PATH. You could just assume that anyone using Linux is going to know all this already,… Read more »
Wesley
Guest
Thank you for the directions, however… I don’t get it. I downloaded the complete package, and now I have no idea what to do with it on a Mac. I’m just learning APIs, and wanted to try some things with Google Calendar’s API. I don’t know Bash commands (DOS commands almost work lol…), I don’t know how to move Gradle from where it was downloaded to where it should go. Would be super nice (and probably super easy) if it just had some kind of executable that installed it in the proper location. When I run the Gradle executable, it… Read more »
Abhishek
Guest
I downloaded the complete package, and now I have no idea what to do with it on a Mac. I’m just learning APIs, and wanted to try some things with Google Calendar’s API. I don’t know Bash commands (DOS commands almost work lol…), I don’t know how to move Gradle from where it was downloaded to where it should go. Would be super nice (and probably super easy) if it just had some kind of executable that installed it in the proper location. When I run the Gradle executable, it looks like it’s doing…. something? Whatever it’s doing, it’s not… Read more »
wpDiscuz