Grails

How To Install Grails on Ubuntu 24.04 Or Newer

Welcome to the Greenhost.cloud blog! Today, we’ll dive into the world of Grails, a powerful web application framework that simplifies the development of web applications in the Groovy programming language. Whether you’re building a small project or a large enterprise application, Grails can help speed up your development process. In this post, we’ll guide you through the steps to install Grails on Ubuntu 24.04 or newer.

Prerequisites

Before we start, make sure you have the following:

  1. Ubuntu 24.04 or newer: Ensure your system is up to date.
  2. Java Development Kit (JDK): Grails requires JDK version 8 or newer. We recommend using OpenJDK.
  3. Terminal Access: You’ll need to use the command line for installation.

Step 1: Update Your System

Open a terminal and update your package list to ensure you have the latest information on available packages:

sudo apt update && sudo apt upgrade -y

Step 2: Install OpenJDK

Grails runs on the Java Virtual Machine, so the first step is to install OpenJDK. You can choose to install OpenJDK 11 or OpenJDK 17, as both are compatible with Grails.

To install OpenJDK 11, run the following command:

sudo apt install openjdk-11-jdk -y

To install OpenJDK 17, use:

sudo apt install openjdk-17-jdk -y

Step 3: Verify Java Installation

After installing the JDK, you can verify the installation by checking the Java version:

java -version

You should see output indicating that Java is installed, along with its version number.

Step 4: Download Grails

Next, we’ll download Grails. At the time of writing, the latest version can be found on the Grails website. Use the following command to download the latest version (replace x.x.x with the latest version number):

wget https://github.com/grails/grails-core/releases/download/vx.x.x/grails-x.x.x.zip

Step 5: Install Grails

Once the download is complete, unzip the Grails package:

unzip grails-x.x.x.zip

Move the unzipped Grails folder to /opt for easier access:

sudo mv grails-x.x.x /opt/grails

Step 6: Set Up Environment Variables

To use Grails from any terminal session, you need to set up environment variables. Open the .bashrc file in your home directory:

nano ~/.bashrc

Add the following lines at the end of the file:

export GRAILS_HOME=/opt/grails
export PATH=$PATH:$GRAILS_HOME/bin

Save the file and exit the editor (in nano, you can do this by pressing CTRL + X, then Y, and ENTER).

Step 7: Apply the Changes

To apply the changes to your current terminal session, run:

source ~/.bashrc

Step 8: Verify Grails Installation

To confirm that Grails is installed correctly, check the version by running:

grails -version

You should see the version of Grails that you installed.

Step 9: Create Your First Grails Application

Now that Grails is installed, let’s create a simple application to ensure everything is working:

grails create-app my-first-app

Change to the application directory:

cd my-first-app

Run the application:

grails run-app

You should see output indicating that the application is running, and you can access it by navigating to http://localhost:8080 in your web browser.

Conclusion

Congratulations! You’ve successfully installed Grails on Ubuntu 24.04 or newer. With Grails, you can now start building robust web applications using Groovy. Be sure to check out the official Grails documentation for more tips, tutorials, and advanced features.