How to install Groovy on Linux system-wide

Groovy Logo
Image by Zorak1103 – CC BY-SA 3.0

(see section UPDATE at the bottom of the post to install Groovy using sdkman)

A colleague of mine recently asked me to install the Groovy programming language on our Red Hat 6.5 server and to make it accessible to all users. I thought it would be a very straightforward task but a quick search on the Red Hat 6.5 official repositories didn’t return any package for Groovy.

The easiest way to install Groovy manually is via gvm. I followed this  procedure to do it:

  1. Log in as root
sudo -i

2.  Retrieve the gvm install script and store it in a temporary file

curl –s get.gvmtool.net > /tmp/gvm.sh

3. Make the temporary file executable

chmod +x /tmp/gvm.sh

4. Run the install script

./tmp/gvm.sh

5. Complete the installation as requested at prompt

source "/root/.gvm/bin/gvm-init.sh"

6. Check that gvm is installed (this should return the help message explaining how to use gvm)

gvm help

7. Remove the temporary install script

rm /tmp/gvm.sh

8. Install groovy via gvm

gvm install groovy

9. Select the current version of groovy as default (at the time of writing version 2.4.3)  and check that groovy is installed

groovy -version
Groovy Version: 2.4.3 JVM: 1.7.0_79 Vendor: Oracle Corporation OS: Linux

10. Create a symlink to use groovy system-wide

ln -s /root/.gvm/groovy/current/bin/groovy /usr/bin/groovy

11. Exit the root user

exit

12. Check that groovy is installed system-wide

whereis groovy
groovy: /usr/bin/groovy

 

UPDATE:

Recently I had to install groovy on other Linux systems and discovered that that it is now much easier using sdkman, which is the evolution of gvm. This is the procedure to follow:

  1. Make sure you have Java installed by running:
java -version

If you don’t have Java, follow these instructions to install the default JRE/JDK or Oracle JDK.

2.  Install sdkman and set it up:

curl -s "https://get.sdkman.io" | bash
source "/home/cirulls/.sdkman/bin/sdkman-init.sh"

3. Check that sdkman is correctly installed:

sdk version

4. Install groovy:

sdk install groovy

5. Check that groovy is correctly installed:

groovy -version

 

Happy grooving!

Leave a Reply

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