install groovy

How to install Groovy on Ubuntu 20.04 LTS

Apache Groovy is a Object Oriented programming language which is compatible with Java syntax.It is both static and dynamic language. You can use the Apache Groovy either as a scripting or programming language.

As a DevOps engineer, you might have known the use of Groovy script in Jenkins Pipeline.

Requirement

1. Groovy 3.x (At the time of writing this is the stable latest version)
2. JDK 1.8+ (Java version more than 1.8)

Install OpenJDK

For Java, we will install OpenJDK. Here we will install OpenJDK-14 version. If you want to install some other OpenJDK version, first check which OpenJDK version is available in Ubuntu Repo – to find, use command sudo apt search openjdk for this.

a. Open the terminal. Click on ‘Activities’ and in search type ‘terminal’ then click on ‘Terminal’ icon.

b. Install OpenJDK 14 version

sudo apt install openjdk-14-jdk*
sudo apt install openjdk-14-jre*

c. Set the environment for Java. For this, edit the file .bashrc of login user.

vi ~/.bashrc

Add these two lines at the end of line ~/.bashrc

export JAVA_HOME=/usr/lib/jvm/java-14-openjdk-amd64/
export PATH=$JAVA_HOME/bin:$PATH

d. Apply the Java environment without reboot.

source ~/.bashrc

Now move to section, “How to install Groovy 3.x”

How to install Groovy 3.x

To make the things simple in Ubuntu 20.04 LTS, we will use the snap package managee.

a. Open the terminal. Click on ‘Activities’ and in search type ‘terminal’ then click on ‘Terminal’ icon.

b. Run the given below command to install Groovy 3.x.

sudo snap install groovy --classic

c. Once installed, check the Groovy version by hitting the command – groovy --version

Output from our system:

sharad@linuxworld:~$ groovy --version
Groovy Version: 3.0.4 JVM: 14.0.1 Vendor: Private Build OS: Linux
sharad@linuxworld:~$ 

To open Groovy Console, go to ‘Activities’ and in search type ‘Groovy’. Click ‘Console For Ap…’ icon. It will open the Groovy Console.
groovy console

You can write in Groovy Console and run the code.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.