LOGOCOMP2511

🐧 Linux/WSL (Ubuntu)
Public

Setting up your local development environment for Java on Linux/WSL (Ubuntu).

Warning
  • This guide is for local setup. If you are working on CSE, you do not need to follow this.
  • It is recommended to setup development locally in-case you need to use it.
  • It is highly recommended to use WSL2 instead of WSL1.
Tip

This guide is for the Ubuntu distro. Other distro's will follow very similar steps which you can look up.

1. Installing Java JDK 17 On Your Machine

Warning

It is important that you install exactly Java JDK version 17.x on your machine.

This is how we will be compiling and testing your code.

To install the JDK:

  1. Run sudo apt update
  2. Run sudo apt install openjdk-17-jdk -y
  3. Verify installation using the command:
java --version

The output should look like the following (doesn't need to be identical. Most importantly needs to show Java 17)

openjdk 17.0.9 2023-10-17
OpenJDK Runtime Environment (build 17.0.9+9-Ubuntu-122.04)
OpenJDK 64-Bit Server VM (build 17.0.9+9-Ubuntu-122.04, mixed mode, sharing)

If you get a different major version number, despite installing Java 17, you may need to configure your system to default to Java 17.

sudo update-alternatives --config java

For example, for the output below, 2 should be entered to choose java-17-openjdk.

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           java-21-openjdk.x86_64 (/usr/lib/jvm/java-21-openjdk-21.0.4.0.7-2.fc40.x86_64/bin/java)
   2           java-17-openjdk.x86_64 (/usr/lib/jvm/java-17-openjdk-17.0.12.0.7-2.fc40.x86_64/bin/java)

Enter to keep the current selection[+], or type selection number:

2. Gradle 8.8 Installation

Note

It is important you install exactly Gradle 8.8.

  1. Download the Gradle zip file by running:

This will download the file into whatever directory you're currently in.

You can pick any directory you want, but if you are unsure, navigate to your Downloads directory using the command: cd ~/Downloads

If you are getting an error of "no such directory found", you can create the Downloads directory by using the command: mkdir -p ~/Downloads then running the cd ~/Downloads command again.

wget https://downloads.gradle.org/distributions/gradle-8.8-bin.zip

Alternatively, you can navigate to this link to download it via a browser here.

  1. Check the zip file is in your current directory.
ls -la

A file called gradle-8.8-bin.zip should exist in the output.

  1. Run sudo mkdir -p /opt/gradle.
  2. Run sudo unzip -d /opt/gradle gradle-8.8-bin.zip

If you don't have unzip. You can install it via sudo apt install unzip.

This command is also assuming that you're in the directory where the gradle-8.8-bin.zip file exists.

  1. Check Gradle was successfully unzipped by running ls /opt/gradle/gradle-8.8.

The following output should be expected:

LICENSE	NOTICE	README	bin	init.d	lib
  1. Now we need to add this Gradle installation to our path so we can use it in our terminal:
printf '\nexport PATH="$PATH:/opt/gradle/gradle-8.8/bin"\n' >> ~/.bashrc

This command assumes that you are using the bash shell. If you are using zsh, replace ~/.bashrc with ~/.zshrc. For other shells, you will have to look this up yourself.

  1. Reload your terminal configuration by running source ~/.bashrc. This will apply any changes made to the ~/.bashrc file in step 6.
  2. Verify installation by running gradle --version

The following output is expected:

------------------------------------------------------------
Gradle 8.8
------------------------------------------------------------

Build time:   2024-05-31 21:46:56 UTC
Revision:     4bd1b3d3fc3f31db5a26eecb416a165b8cc36082

Kotlin:       1.9.22
Groovy:       3.0.21
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          17.0.11 (Homebrew 17.0.11+0)
OS:           Linux 5.15.153.1-microsoft-standard-WSL2 amd64

The most important things to note are Gradle 8.8 and JMV: 17.x.y.

Last updated on

On this page