UbuntuUbuntu Based

How To Install Apache Groovy on Ubuntu 24.04 LTS

Install Apache Groovy on Ubuntu 24.04

Apache Groovy has become an essential tool in the software development landscape, offering a powerful and flexible programming language for the Java platform. As businesses and developers increasingly adopt Ubuntu as their preferred operating system, understanding how to install and configure Groovy on Ubuntu 24.04 is crucial. This comprehensive guide will walk you through the process of installing Apache Groovy on Ubuntu 24.04, ensuring you have the latest version up and running smoothly on your system.

What is Apache Groovy?

Apache Groovy is a dynamic, object-oriented programming language for the Java Virtual Machine (JVM). It seamlessly integrates with Java code and libraries, making it an excellent choice for developers looking to enhance their Java projects with more concise and expressive code. Groovy offers several advantages, including:

  • Simplified syntax compared to Java
  • Dynamic typing for faster development
  • Built-in support for functional programming concepts
  • Powerful metaprogramming capabilities
  • Excellent for scripting and automation tasks

Developers commonly use Groovy for web development, test automation, build scripting, and creating domain-specific languages (DSLs). Its versatility makes it a valuable addition to any Java developer’s toolkit.

Prerequisites for Installing Groovy on Ubuntu 24.04

Before diving into the installation process, ensure your Ubuntu 24.04 system meets the following requirements:

  • A 64-bit Ubuntu 24.04 LTS installation
  • At least 2GB of RAM (4GB recommended)
  • Sufficient disk space (at least 500MB free)
  • An active internet connection
  • Administrative (sudo) access to your system

Additionally, you’ll need to have Java Development Kit (JDK) installed on your system, as Groovy runs on the Java Virtual Machine (JVM).

Preparing Your Ubuntu 24.04 System

Before installing Groovy, it’s essential to update your system and ensure you have the latest Java Development Kit installed. Follow these steps to prepare your Ubuntu 24.04 system:

1. Update System Packages

Open a terminal and run the following commands to update your system packages:

sudo apt update
sudo apt upgrade -y

2. Install Java Development Kit (JDK)

Groovy requires Java to run. Install the default JDK using the following command:

sudo apt install default-jdk -y

3. Verify Java Installation

After installation, verify that Java is correctly installed by checking its version:

java -version

You should see output similar to this:

openjdk version "17.0.x" 2024-xx-xx
OpenJDK Runtime Environment (build 17.0.x+x-Ubuntu-0ubuntu1.24.04)
OpenJDK 64-Bit Server VM (build 17.0.x+x-Ubuntu-0ubuntu1.24.04, mixed mode, sharing)

4. Configure Java Environment Variables

Set the JAVA_HOME environment variable by adding the following line to your ~/.bashrc file:

echo 'export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")' >> ~/.bashrc
source ~/.bashrc

Verify the JAVA_HOME variable is set correctly:

echo $JAVA_HOME

Methods to Install Apache Groovy

There are three primary methods to install Apache Groovy on Ubuntu 24.04:

  1. Using SDKMAN (Software Development Kit Manager)
  2. Manual installation from binary package
  3. Using the apt package manager

We’ll explore each method in detail, allowing you to choose the one that best suits your needs.

Installing Groovy Using SDKMAN

SDKMAN is a popular tool for managing multiple versions of various software development kits. It simplifies the process of installing and switching between different versions of Groovy and other JVM-based tools.

1. Install SDKMAN

To install SDKMAN, run the following command:

curl -s "https://get.sdkman.io" | bash

After installation, close and reopen your terminal or run:

source "$HOME/.sdkman/bin/sdkman-init.sh"

2. Install Groovy using SDKMAN

With SDKMAN installed, you can easily install the latest version of Groovy:

sdk install groovy

This command will download and install the most recent stable version of Groovy.

3. Verify Groovy Installation

Check the installed Groovy version:

groovy --version

4. Switch Between Groovy Versions

SDKMAN allows you to install and switch between multiple Groovy versions. To list available versions:

sdk list groovy

To install a specific version:

sdk install groovy 4.0.11

To switch to a different installed version:

sdk use groovy 4.0.11

Manual Installation of Apache Groovy

For users who prefer more control over the installation process, manual installation is an excellent option. Follow these steps to manually install Groovy on Ubuntu 24.04:

1. Download Groovy Binary Package

Visit the official Apache Groovy download page and copy the link for the latest binary release. Then, use wget to download it:

wget https://groovy.jfrog.io/artifactory/dist-release-local/groovy-zips/apache-groovy-binary-4.0.11.zip

2. Extract the Groovy Package

Unzip the downloaded file:

unzip apache-groovy-binary-4.0.11.zip

3. Move Groovy Files

Move the extracted directory to /opt:

sudo mv groovy-4.0.11 /opt/groovy

4. Set Up Groovy Environment Variables

Add Groovy to your system’s PATH by editing ~/.bashrc:

echo 'export GROOVY_HOME=/opt/groovy' >> ~/.bashrc
echo 'export PATH=$PATH:$GROOVY_HOME/bin' >> ~/.bashrc
source ~/.bashrc

5. Verify the Installation

Check if Groovy is correctly installed:

groovy --version

Installing Groovy via apt Package Manager

Ubuntu’s package manager, apt, offers a straightforward way to install Groovy. However, the version available might not always be the latest. Here’s how to install Groovy using apt:

1. Add Groovy Repository

First, add the Groovy repository to your system:

sudo add-apt-repository ppa:groovy-dev/groovy

2. Update Package Lists

Update your package lists to include the new repository:

sudo apt update

3. Install Groovy

Install Groovy using apt:

sudo apt install groovy -y

4. Verify Installation

Check the installed Groovy version:

groovy --version

While this method is simple, it may not provide the most recent Groovy version. Consider using SDKMAN or manual installation for the latest releases.

Verifying Groovy Installation

Regardless of the installation method you chose, it’s crucial to verify that Groovy is working correctly on your Ubuntu 24.04 system.

1. Check Groovy Version

Run the following command to display the installed Groovy version:

groovy --version

2. Run a Simple Groovy Script

Create a file named test.groovy with the following content:

println "Hello, Groovy on Ubuntu 24.04!"

Run the script using:

groovy test.groovy

If you see the output “Hello, Groovy on Ubuntu 24.04!”, your Groovy installation is working correctly.

Troubleshooting Common Issues

If you encounter any problems, check the following:

  • Ensure JAVA_HOME and GROOVY_HOME are correctly set in your ~/.bashrc file
  • Verify that the Groovy bin directory is in your PATH
  • Check for any error messages during the installation process
  • Make sure you have sufficient permissions to execute Groovy

Configuring Groovy for Development

To make the most of Groovy in your development workflow, consider the following configurations:

Setting up Groovy in Popular IDEs

  • IntelliJ IDEA: Install the Groovy plugin and configure the Groovy SDK in Project Structure settings.
  • Eclipse: Install the Groovy-Eclipse plugin and set up the Groovy compiler in project properties.
  • Visual Studio Code: Install the Groovy Language extension and configure the Groovy path in settings.

Configuring Build Tools

Integrate Groovy with popular build tools:

  • Gradle: Add the Groovy plugin to your build.gradle file:
    apply plugin: 'groovy'
  • Maven: Include the GMavenPlus plugin in your pom.xml:
    <plugin>
        <groupId>org.codehaus.gmavenplus</groupId>
        <artifactId>gmavenplus-plugin</artifactId>
        <version>2.1.0</version>
        <executions>
            <execution>
                <goals>
                    <goal>compile</goal>
                    <goal>compileTests</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

Congratulations! You have successfully installed Apache Groovy. Thanks for using this tutorial for installing Apache Groovy programming language on Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Apache Groovy website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button