How to install Groovy on Amazon Linux 2 machine

Photo by Jon Tyson on Unsplash

How to install Groovy on Amazon Linux 2 machine

Overview:

Amazon Linux 2 machine (centos rhel fedora)
To check version of the machine use:

cat /etc/os-release

Groovy is a scripting language with Java-like syntax for the Java platform. It is managed by Apache Software Foundation.

This post shows how to install Groovy via SDKMan

Install SDKMan:

  1. Download SDKMAN:
    curl -s "https://get.sdkman.io" | bash
    
  2. Execute installation script and populate variables:
    source "$HOME/.sdkman/bin/sdkman-init.sh"
    
  3. Check if the installation has succeded:
    sdk version
    

Java configuration:

  1. Ensure that you have Java installed on your machine:
    java --version
    
  2. Copy the path to the Java folder:
    ls /usr/lib/jvm
    
  3. Set JAVA_HOME environment variable:
    vim ~/.bashrc
    
  4. Add the following entries, close and save the file:
    export JAVA_HOME="/usr/lib/jvm/[java_folder]/"
    export PATH=$PATH:$JAVA_HOME/bin
    
  5. Load variables:
    source ~/.bashrc
    

Groovy install:

  1. Set the executable bit on sdkman-init.sh:
    chmod +x ~/.sdkman/bin/sdkman-init.sh
    
  2. Install Groovy:
    sdk install groovy
    
  3. Check groovy version:
    groovy -version
    

Notes:

  1. source is a built-in shell command that reads and executes the file content in the current shell. These files usually contain a list of commands.
  2. . bash_profile and . bashrc are files containing shell commands that are run when Bash is invoked

Reference:

  1. Amazon Linux 2
  2. Install Groovy
  3. SDK install
  4. getting 'internet not reachable' with sdkman
  5. How to set JAVA_HOME in Linux for all users