The Personal Blog of Todd Sharp

Grails on Raspberry Pi Part 3 - Installing Groovy And Grails

Posted By: Todd Sharp on 3/16/2017 8:27 GMT
Tagged: Grails, Groovy, Groovy On Raspberry Pi, Java, Raspberry Pi

The first step in getting working with Grails on the Raspberry Pi is, of course, installing Grails.  I've been somewhat dreading this post because it's pretty hard to make installing software interesting, but it's necessary so we'll trudge through it and try to have a good time with it.  If you've never worked with Groovy or Grails before, that's quite alright.  I'll do my best to make sure that I keep things basic, but at the same time you might want to run through some Groovy or Grails tutorials (there are plenty out there).  Also, feel free to ask questions.  My goal is to help you get a web site up and running on the Raspberry Pi.

There are two ways to install Grails.  One way is to download it yourself, and the right way is to install SDKMAN and use it to install Grails for you.  Follow the instructions on the Grails download page to install SDKMAN, but before you do make sure that you have "zip" installed first via:

sudo apt-get install zip

Note:  SDKMAN will prompt you to run the following command after it installs:

Please open a new terminal, or run the following in the existing one:
source "/home/pi/.sdkman/bin/"

Don't skip this step, else you'll get errors complaining that "sdk: command not found".  Once SDKMAN is installed, install Grails via:

sdk install grails

Seriously, that's all it takes. Since you didn't pass a specific version to SDKMAN it'll grab the latest version and install it (which is 3.2.7 as of the time this post was published).  

Well, I kinda lied - if you actually want to run Grails, you'll have to set the JAVA_HOME environment variable so that Grails knows where Java is.  After you set JAVA_HOME, run:

grails -version

Since Grails uses the Groovy language, it'll also install the required Groovy version, but I typically like to also install a standalone version of Groovy for one off scripts and testing purposes.  To install Groovy, just do:

sdk install groovy

I typically also create a folder called "Projects" in my home directory so feel free to do something similar at this point.  If you want to create a simple test Groovy script, create a file called test.groovy and enter the following using nano (or vi if you're crazy):

println new Date().format('MM-dd-yyyy')

Run it from the command line with:

groovy test.groovy

And it'll output the current date.  

And that's all it takes to get Groovy and Grails installed on the Raspberry Pi.  In the next post we'll look at creating a slightly more complex Groovy script to illustrate how easy it is to use for simple scripting and even more complex tasks.

Image by Comfreak from Pixabay

Related Posts

The Complete Guide To Invoking Serverless Oracle Functions

The Complete Guide To Invoking Serverless Oracle Functions

I have blogged quite a bit about serverless Oracle Functions here on this blog, including several various examples about function invocation. But, I've...

Building Cross Platform Native Images With GraalVM

Building Cross Platform Native Images With GraalVM

A few weeks ago, I blogged about a utility that I created that helps you debug your serverless functions in the Oracle Cloud. The code behind that project...

Simple Serverless Logging For Oracle Functions

Simple Serverless Logging For Oracle Functions

Working with serverless functions represents a new way of thinking for many developers. Dealing with stateless functions, for example, can be a challenge...

Note: Comments are currently closed on this blog. Disqus is simply too bloated to justify its use with the low volume of comments on this blog. Please visit my contact page if you have something to say!