How to Install Apache Groovy on Ubuntu 22.04 (Step-by-Step Guide)

Apache Groovy is a powerful, flexible, and dynamic programming language built for the Java platform. It is widely used for scripting, testing automation, and building applications thanks to its concise syntax and seamless integration with Java libraries.
If you are working on Ubuntu 22.04 (Jammy Jellyfish) and want to install Apache Groovy, this guide will walk you through the process step by step.
What is Apache Groovy?
Apache Groovy is an object-oriented programming language that extends Java’s capabilities with scripting features. It is designed to improve developer productivity by providing:
- Concise and readable syntax.
- Support for scripting and domain-specific languages (DSLs).
- Compatibility with existing Java code.
- Built-in support for JSON, XML, regular expressions, and more.
Because Groovy runs on the Java Virtual Machine (JVM), you’ll need to install Java Development Kit (JDK) before using Groovy.
Prerequisites
Before installing Apache Groovy on Ubuntu 22.04, make sure you have:
- A system running Ubuntu 22.04.
- A user account with sudo privileges.
- An internet connection.
Step 1: Update System Packages
It’s always a good practice to update your package list before installing new software. Run the following commands:
sudo apt update && sudo apt upgrade -y
This ensures you are working with the latest package versions.
Step 2: Install Java (JDK)
Since Apache Groovy requires Java, we need to install OpenJDK 11 or later.
sudo apt install openjdk-11-jdk -y
Verify the installation:
java -version
Expected output:
openjdk version "11.0.x" 2023-xx-xx
Step 3: Download Apache Groovy
Apache Groovy is not always available in Ubuntu’s default repositories, so it’s recommended to download it from the official Apache Groovy website.
Navigate to the Groovy download page and copy the link of the latest stable binary distribution.
For example (replace version with the latest available):
wget https://dl.bintray.com/groovy/maven/apache-groovy-binary-4.0.14.zip
Step 4: Extract Apache Groovy
After downloading the .zip
archive, extract it using the unzip
command. If unzip
is not installed, install it first:
sudo apt install unzip -y
Then extract Groovy:
unzip apache-groovy-binary-4.0.14.zip
Move the extracted folder to /opt
for easier management:
sudo mv groovy-4.0.14 /opt/groovy
Step 5: Configure Environment Variables
To make Groovy accessible system-wide, add it to the environment variables.
Open your shell profile file:
nano ~/.bashrc
Add the following lines at the bottom:
export GROOVY_HOME=/opt/groovy
export PATH=$GROOVY_HOME/bin:$PATH
Save and apply the changes:
source ~/.bashrc
Step 6: Verify Installation
Check if Groovy is installed correctly by running:
groovy --version
Expected output:
Groovy Version: 4.0.14 JVM: 11.0.17 Vendor: Ubuntu OS: Linux

If you see the version, Apache Groovy is successfully installed on your Ubuntu 22.04 system.
Step 7: Test Groovy Script
Let’s run a simple Groovy script to verify functionality.
Create a file named hello.groovy
:
nano hello.groovy
Insert the following code:
println "Hello, Apache Groovy on Ubuntu 22.04!"
Save the file and run:
groovy hello.groovy
Output:
Hello, Apache Groovy on Ubuntu 22.04!
Uninstalling Groovy (Optional)
If you ever need to remove Groovy:
- Delete the Groovy installation directory:
sudo rm -rf /opt/groovy
- Remove Groovy environment variables from
~/.bashrc
.
Conclusion
Installing Apache Groovy on Ubuntu 22.04 is straightforward if you follow the right steps. To summarize:
- Update system packages.
- Install Java (JDK).
- Download the latest Groovy binary from the official site.
- Extract and configure environment variables.
- Verify installation and run test scripts.
Now you are ready to use Apache Groovy for scripting, automation, and application development on your Ubuntu 22.04 machine.