Friends, in this post, we will show you how to install Apache Groovy on Ubuntu 20.04 / Debian 10.
Citing Groovy’s website we get the following explanation:
Groovy is a powerful, optionally typed and dynamic language, with static-typing and static compilation capabilities, for the Java platform aimed at improving developer productivity thanks to a concise, familiar and easy to learn syntax.
Therefore, it is possible to say that Groovy is a kind of evolution of Java, but it is not a different language. Some of the features of Apache Groovy are the following:
- Pretty low learning curve. Thanks to the clear and readable syntax it has.
- Also, Groovy integrates perfectly with any Java application.
- It has a very complete and varied ecosystem.
So knowing about Groovy is a good idea if you like Java very much or if you want to specialize in it.
Install Groovy on Ubuntu 20.04 / Debian 10
Like almost everything in Linux, the installation of Groovy can be done in several ways. So you can choose which one suits you best and have your criteria.
Before you start, remember that Groovy requires you to have Java installed on your system. So make sure you do.
:~$ sudo apt install openjdk-11-jdk Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: adwaita-icon-theme at-spi2-core ca-certificates-java fontconfig fonts-dejavu-extra glib-networking glib-networking-common glib-networking-services gsettings-desktop-schemas gtk-update-icon-cache hicolor-icon-theme java-common libatk-bridge2.0-0 libatk-wrapper-java libatk-wrapper-java-jni libatk1.0-0 libatk1.0-data libatspi2.0-0 libcairo-gobject2 libcroco3 libdatrie1 libepoxy0 libfribidi0 libgail-common libgail18 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-bin libgdk-pixbuf2.0-common libgif7 libgraphite2-3 libgtk-3-0 libgtk-3-bin libgtk-3-common libgtk2.0-0 libgtk2.0-bin libgtk2.0-common libharfbuzz0b libice-dev libjson-glib-1.0-0 libjson-glib-1.0-common libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libproxy1v5 libpthread-stubs0-dev librest-0.7-0 librsvg2-2 librsvg2-common libsm-dev libsoup-gnome2.4-1 libsoup2.4-1 libthai-data libthai0 libwayland-client0 libwayland-cursor0 libwayland-egl1 libx11-dev libxau-dev libxcb1-dev libxcursor1 libxdmcp-dev libxkbcommon0 libxt-dev openjdk-11-jdk-headless openjdk-11-jre openjdk-11-jre-headless x11proto-core-dev x11proto-dev xorg-sgml-doctools xtrans-dev Suggested packages: default-jre gvfs libice-doc librsvg2-bin libsm-doc libx11-doc libxcb-doc libxt-doc openjdk-11-demo openjdk-11-source visualvm fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei | fonts-wqy-zenhei fonts-indic The following NEW packages will be installed: adwaita-icon-theme at-spi2-core ca-certificates-java fontconfig fonts-dejavu-extra glib-networking glib-networking-common glib-networking-services gsettings-desktop-schemas gtk-update-icon-cache hicolor-icon-theme java-common libatk-bridge2.0-0 libatk-wrapper-java libatk-wrapper-java-jni libatk1.0-0 libatk1.0-data libatspi2.0-0 libcairo-gobject2 libcroco3 libdatrie1 libepoxy0 libfribidi0 libgail-common libgail18 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-bin libgdk-pixbuf2.0-common libgif7 libgraphite2-3 libgtk-3-0 libgtk-3-bin libgtk-3-common libgtk2.0-0 libgtk2.0-bin libgtk2.0-common libharfbuzz0b libice-dev libjson-glib-1.0-0 libjson-glib-1.0-common libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libproxy1v5 libpthread-stubs0-dev librest-0.7-0 librsvg2-2 librsvg2-common libsm-dev libsoup-gnome2.4-1 libsoup2.4-1 libthai-data libthai0 libwayland-client0 libwayland-cursor0 libwayland-egl1 libx11-dev libxau-dev libxcb1-dev libxcursor1 libxdmcp-dev libxkbcommon0 libxt-dev openjdk-11-jdk openjdk-11-jdk-headless openjdk-11-jre openjdk-11-jre-headless x11proto-core-dev x11proto-dev xorg-sgml-doctools xtrans-dev 0 upgraded, 71 newly installed, 0 to remove and 0 not upgraded. Need to get 288 MB of archives. After this operation, 527 MB of additional disk space will be used. Do you want to continue? [Y/n]
Now, you can continue.
Installing Groovy from the official Ubuntu 20.04 / Debian 10 repositories
Groovy is becoming more popular every day, and this makes Debian include it in its repositories. This method although quite easy and oriented to newcomers, may not be completely useful because you do not get the latest stable version.
So, open a terminal and install it with the following command:
:~$ sudo apt update :~$ sudo apt install groovy
If you do not have sudo enabled on Debian, you can do it with our tutorial.
Then, you can show the installed version with the following command
:~$ groovy -v
And that’s it. As I said, this method, although easy, is not always convenient because we miss the news of the language.
Groovy is available at Homebrew
We talked about Homebrew recently and it is that this community package manager, saves us a lot of time to get recent versions of applications that are not in the official repositories of some distributions.
So Groovy is available for installation using Homebrew. You have to install it first.
And then, just run the following command:
:~$ brew install groovy
This method is also easy but as it is a third party, not many developers prefer it.
Install Groovy using SDKMAN!
The method that combines simplicity and security is this. Using SDKMAN we can get Groovy installed on almost any system. We are talking about a powerful script that does all the work for us.
So let’s go for it.
First, open a terminal and run this command to download and execute the script.
:~$ curl -s get.sdkman.io | bash
If you do not have curl installed, you can do it with the following command:
:~$ sudo apt install curl
This script downloads and installs SDKMAN and modifies some things in your profile. So, refresh the changes with the following command:
:~$ source "$HOME/.sdkman/bin/sdkman-init.sh"
Now, proceed to install Groovy on Ubuntu 20.04 / Debian 10.
:~$ sdk install groovy
After the installation is complete, you can display the version of Groovy or another option:
:~$ groovy -v
And that’s it.
Install Groovy on Ubuntu 20.04 / Debian 10 using a binary distribution
Another way to install it is through the binary package compiled for Linux or any system with Java.
This procedure guarantees greater flexibility because we can copy it wherever we want and also guarantees to have the last stable version of Groovy.
Maybe this method is a little more complex than the previous ones, but it is the best for many developers.
So, open a terminal and download the zip file with the program. You can do this from the temporary folder.
:~$ cd /tmp/ :~$ wget -c https://bintray.com/artifact/download/groovy/maven/apache-groovy-binary-3.0.4.zip
At the time of this post, the last stable version of Groovy is 3.0.4, check it before executing the commands.
After the download is finished, you can unzip it using the unzip command. We’ll take advantage of this, to unzip it in a different and permanent folder like /opt/
:~$ sudo unzip apache-groovy-binary-3.0.4.zip -d /opt/groovy
In case you do not have the unzip command installed, just install it.
:~$ sudo apt install unzip zip
After that, modify your profile file and add the path where you unzipped Groovy. In this case, it would look like this
:~$ nano ~/.profile
export JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64 export GROOVY_HOME=/opt/groovy/groovy-3.0.4/ export PATH=$GROOVY_HOME/bin:$PATH
Save the changes and close the file.
Apply the changes with the following command:
:~$ source ~/.profile
And now I do. Now Groovy is ready for battle. You can check the operation of the command, for example by showing the help it provides:
:~$ groovy --help Usage: groovy [options] [filename] [args] The Groovy command line processor. -cp, -classpath, --classpath=<path> Specify where to find the class files - must be first argument -D, --define=<property=value> Define a system property --disableopt=optlist[,optlist...] Disables one or all optimization elements; optlist can be a comma separated list with the elements: all (disables all optimizations), int (disable any int based optimizations) -d, --debug Debug mode will print out full stack traces -c, --encoding=<charset> Specify the encoding of the files -e=<script> Specify a command line script -i=[<extension>] Modify files in place; create backup if extension is given (e.g. '.bak') -n Process files line by line using implicit 'line' variable -p Process files line by line and print result (see also -n) -pa, --parameters Generate metadata for reflection on method parameter names (jdk8+ only) -pr, --enable-preview Enable preview Java features (JEP 12) (jdk12+ only) -l=[<port>] Listen on a port and process inbound lines (default: 1960) -a, --autosplit[=<splitPattern>] Split lines using splitPattern (default '\s') using implicit 'split' variable --indy Enables compilation using invokedynamic --configscript=<script> A script for tweaking the configuration options -b, --basescript=<class> Base class name for scripts (must derive from Script) -h, --help Show this help message and exit -v, --version Print version information and exit
So, enjoy it.
Apache Groovy does not replace Java but rather reinforces its use and utility thanks to it. With Groovy you can implement a simple, fast and expressive language that is capable of being compatible with Java and thus facilitate the creation of applications.
Please share this post and join our Telegram channel.