Installing Groovy on macOS

One of the new tasks I am executing in my new job is to write scripts in Groovy. Apache Groovy is, as Wikipedia well defines it, a dynamic object-oriented programming language with features similar to those of Python and Ruby, but for the Java platform. It can be used as a scripting language, is dynamically compiled to Java virtual machine (JVM) bytecode, and interoperates with other Java code and libraries.

The best way to have Groovy working on a macOS X machine is by installing the SDKMAN (Software Development Kit Manager). It manages the installation of Groovy on any Bash platform (then, not only for macOS boxes) as simple as you can slice a piece of cake.

To install the SDKMAN, open your terminal and follow this process:

$ curl -s get.sdkman.io | bash
                                       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.6.2+294 ...
Attempt update of login bash profile on OSX...
Added sdkman init snippet to /Users/pvital/.bash_profile
Attempt update of zsh profile...
Updated existing /Users/pvital/.zshrc


All done!


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

    source "/Users/pvital/.sdkman/bin/sdkman-init.sh"

Then issue the following command:

    sdk help

Enjoy!!!
$ source "/Users/pvital/.sdkman/bin/sdkman-init.sh”
$ sdk help
==== BROADCAST ======================================================
* 12/03/18: Groovyserv 1.2.0 released on SDKMAN! #groovyserv
* 07/03/18: Grails 3.3.3 released on SDKMAN! #grailsfw
* 06/03/18: Groovy 2.6.0-alpha-3 released on SDKMAN! #groovylang
=====================================================================

Usage: sdk <command> [candidate] [version]
       sdk offline <enable|disable>

   commands:
       install   or i    <candidate> [version]
       uninstall or rm   <candidate> <version>
       list      or ls   [candidate]
       use       or u    <candidate> [version]
       default   or d    <candidate> [version]
       current   or c    [candidate]
       upgrade   or ug   [candidate]
       version   or v
       broadcast or b
       help      or h
       offline           [enable|disable]
       selfupdate        [force]
       update
       flush             <candidates|broadcast|archives|temp>

   candidate  :  the SDK to install: groovy, scala, grails, gradle, 
                 kotlin, etc.
                 use list command for comprehensive list of candidates
                 eg: $ sdk list

   version    :  where optional, defaults to latest stable if not 
                 provided
                 eg: $ sdk install groovy
$

At this point you have SDKMAN installed. Now you can use it to install Groovy:

$ sdk install groovy

Downloading: groovy 2.4.14

In progress...

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

Installing: groovy 2.4.14
Done installing!



Setting groovy 2.4.14 as default.
$

Great! You have Groovy installed and configured on your machine. Let’s check it:

$ groovy -version
Unable to find any JVMs matching version "(null)".
No Java runtime present, try --request to install.
groovy: JAVA_HOME is not defined correctly, can not execute: java
$

OOOPS!!!

As mentioned before, Groovy is a programming language for the Java platform. So, looks like it is necessary to have Java installed before you be able to execute any Groovy script. To install the latest JDK version on your macOS, follow these steps:

  1. Download the jdk-8u<version>-macosx-x64.dmg file from here;
  2. Open the downloaded .dmg file;
  3. Double-click the .pkg file to launch the installer;
  4. Follow the installation process;
  5. After the installation finishes, set the JAVA_HOME environment variable by adding the following line on your ˜/.bash_profile file:
export JAVA_HOME=$(/usr/libexec/java_home)

Source your ˜/.bash_profile file and check if the JAVA_HOME variable and Java are configured correctly:

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
$ java -version
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)
$

Perfect! Now with Java properly installed and configured you can check Groovy installation:

$ groovy -version
Groovy Version: 2.4.14 JVM: 1.8.0_162 Vendor: Oracle Corporation OS: Mac OS X
$

Voilà!!! You have Groovy installed and configured now.

 

Advertisements

GitHub Guides: learning how to work with GitHub.

One of the open source projects or services I really like is GitHub. There you can create your, not only, software projects and use all the huge and great infrastructure to do the version controlling, documentation, issue controlling of your project. In addition, as one of the laggiest computing communities there are, you can easily discover, reuse and contribute to more than 24 million projects.

To help those developers who don’t know how GitHub works, they made available a serie of quick guides explaining each one of it’s most important features and solutions. It’s called GitHub Guides and it’s available at https://guides.github.com. The first guide, in my opinion, is the most important of all guides because explain how the GitHub Flow works. It’s simple and obvious for some experienced developers, but very important for the newcomers.

Also, GitHub provided a several of video guides and trainings explaining how to integrated GitHub with other tools or get mastered in their products. Watch them here: https://www.youtube.com/user/GitHubGuides.

For those interesting in which projects I’ve been contributing or created, check out my profile there: https://github.com/pvital.