(Last Updated On: December 26, 2018)

Being Christmas, let’s look at how to Install Apache Groovy on Ubuntu 18.04 / Ubuntu 16.04. Apache Groovy is a powerful dynamic language for JVM. It has easy to learn syntax, static-typing and compilation capabilities aimed at improving developer productivity.

Groovy integrates well with any Java program to provide features such as domain-specific Language authoring, Scripting capabilities, runtime, and compile-time meta-programming and functional programming.

Follow Steps below to  Install the latest Apache Groovy on Ubuntu 18.04 / Ubuntu 16.04.

Step 1: Update your system

Ensure you are running an up-to-date Ubuntu OS.

sudo apt update
sudo apt -y upgrade
sudo reboot

Step 2: Install Java

Install Java 8:

sudo add-apt-repository ppa:webupd8team/java
sudo apt update
sudo apt install oracle-java8-set-default

Confirm version:

$ java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

Step 3: Download and Run Groovy Installer Script

There are many ways of installing Groovy on Ubuntu 18.04 / Ubuntu 16.04, The easiest and quicker method involves the use of an installer script.

$ curl -s get.sdkman.io | bash

                                -+syyyyyyys:
                            `/yho:`       -yd.
                         `/yh/`             +m.
                       .oho.                 hy                          .`
                     .sh/`                   :N`                `-/o`  `+dyyo:.
                   .yh:`                     `M-          `-/osysoym  :hs` `-+sys:      hhyssssssssy+
                 .sh:`                       `N:          ms/-``  yy.yh-      -hy.    `.N-````````+N.
               `od/`                         `N-       -/oM-      ddd+`     `sd:     hNNm        -N:
              :do`                           .M.       dMMM-     `ms.      /d+`     `NMMs       `do
            .yy-                             :N`    ```mMMM.      -      -hy.       /MMM:       yh
          `+d+`           `:/oo/`       `-/osyh/ossssssdNMM`           .sh:         yMMN`      /m.
         -dh-           :ymNMMMMy  `-/shmNm-`:N/-.``   `.sN            /N-         `NMMy      .m/
       `oNs`          -hysosmMMMMydmNmds+-.:ohm           :             sd`        :MMM/      yy
      .hN+           /d:    -MMMmhs/-.`   .MMMh   .ss+-                 `yy`       sMMN`     :N.
     :mN/           `N/     `o/-`         :MMMo   +MMMN-         .`      `ds       mMMh      do
    /NN/            `N+....--:/+oooosooo+:sMMM:   hMMMM:        `my       .m+     -MMM+     :N.
   /NMo              -+ooooo+/:-....`...:+hNMN.  `NMMMd`        .MM/       -m:    oMMN.     hs
  -NMd`                                    :mm   -MMMm- .s/     -MMm.       /m-   mMMd     -N.
 `mMM/                                      .-   /MMh. -dMo     -MMMy        od. .MMMs..---yh
 +MMM.                                           sNo`.sNMM+     :MMMM/        sh`+MMMNmNm+++-
 mMMM-                                           /--ohmMMM+     :MMMMm.       `hyymmmdddo
 MMMMh.                  ````                  `-+yy/`yMMM/     :MMMMMy       -sm:.``..-:-.`
 dMMMMmo-.``````..-:/osyhddddho.           `+shdh+.   hMMM:     :MmMMMM/   ./yy/` `:sys+/+sh/
 .dMMMMMMmdddddmmNMMMNNNNNMMMMMs           sNdo-      dMMM-  `-/yd/MMMMm-:sy+.   :hs-      /N`
  `/ymNNNNNNNmmdys+/::----/dMMm:          +m-         mMMM+ohmo/.` sMMMMdo-    .om:       `sh
     `.-----+/.`       `.-+hh/`         `od.          NMMNmds/     `mmy:`     +mMy      `:yy.
           /moyso+//+ossso:.           .yy`          `dy+:`         ..       :MMMN+---/oys:
         /+m:  `.-:::-`               /d+                                    +MMMMMMMNh:`
        +MN/                        -yh.                                     `+hddhy+.
       /MM+                       .sh:
      :NMo                      -sh/
     -NMs                    `/yy:
    .NMy                  `:sh+.
   `mMm`               ./yds-
  `dMMMmyo:-.````.-:oymNy:`
  +NMMMMMMMMMMMMMMMMms:`
    -+shmNMMMNmdy+:`


       Now attempting installation...

Looking for a previous installation of SDKMAN...
Looking for unzip...
Looking for zip...
Looking for curl...
Looking for sed...
Installing SDKMAN scripts...
Create distribution directories...
Getting available candidates...
Prime the config file...
Download script archive...
######################################################################## 100.0%
Extract script archive...
Install scripts...
Set version to 5.7.3+337 ...
Attempt update of interactive bash profile on regular UNIX...
Added sdkman init snippet to /home/vagrant/.bashrc
Attempt update of zsh profile...
Updated existing /home/vagrant/.zshrc

All done!

Please open a new terminal, or run the following in the existing one:

    source "/home/vagrant/.sdkman/bin/sdkman-init.sh"

Then issue the following command:
    sdk help

Enjoy!!!

Then run the following in your terminal.

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

The sdkinstall command is now available for you to install the latest stable Groovy on Ubuntu 18.04 / Ubuntu 16.04.

$ sdk install groovy

Sample output:

==== BROADCAST =================================================================
* 24/12/18: Groovy 2.5.5 released on SDKMAN! #groovylang
* 21/12/18: Gradle 5.1-rc-3 released on SDKMAN! #gradle
* 19/12/18: Micronaut 1.0.2 released on SDKMAN! #micronautfw
================================================================================

Downloading: groovy 2.5.5

In progress...

################################################################################################################################################ 100.0%

Installing: groovy 2.5.5
Done installing!

Setting groovy 2.5.5 as default.

After installation is complete test your default version of Groovy with:

$ groovy -version
Groovy Version: 2.5.5 JVM: 1.8.0_191 Vendor: Oracle Corporation OS: Linux

You should now have Groovy installed on your Ubuntu 18.04/16.04 server or Workstation. You can launch Groovy shell by running:

$ groovysh
Dec 25, 2018 11:12:55 AM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
Groovy Shell (2.5.5, JVM: 1.8.0_191)
Type ':help' or ':h' for help.
------------------------------------------------------------------------------------------------------------------------------------------------------
groovy:000>

To run a specific Groovy script type:

$ groovy SomeScript

Hope our guide was helpful in installing Apache Groovy 2.5 on Ubuntu 18.04 / Ubuntu 16.04.

Reference: Apache Groovy Documentation