Skip to content

Setting up Unix for Java Development

hchia edited this page Jun 13, 2024 · 7 revisions

Setting Up Unix for Java Development

Depending on whether you are using a Windows or Mac machine, choose ONE of the following set-ups:

Then test your setup with jshell:

Setup for Windows (through Scoop & mSys)

Step 1: Search Powershell

  • Hit ⊞ Win to open the Start menu, type PowerShell and press Enter.

Step 2: Install the Scoop package manager for Windows

Scoop is a command-line software manager for Windows.

Run the following commands in the PowerShell window one at a time:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
irm get.scoop.sh | iex

To ensure that each command is entered correctly, you may

  • copy the command above by selecting it and then hitting Ctrl + C
  • go to the PowerShell window and paste the command above by hitting Ctrl + V . Press enter to run the command.

Step 3: Install the msys Unix environment

Run the following command in the PowerShell window:

scoop install git

Step 4: Install openjdk21

Run the following commands in the PowerShell window one at a time:

scoop bucket add java
scoop install openjdk21

After all installation is completed, hit ⊞ Win to open the Start menu, type bash and press enter.

To open a File Explorer Window that points to the current directory, enter the following command in the bash window:

explorer.exe .

Note the trailing dot at the end. This will be useful when you select your program for submission to CodeCrunch later.

Setup for Mac

Since the macOS is a Unix-based operating system, there is no setup required.

To access the Unix command line interface, hit F4 to access LaunchPad, and type Terminal followed by enter .

Step 1: Install Command Line Development Tool

Run the following command within Terminal to install a set of command-line tools used for software development in macOS.

xcode-select --install

Step 2: Install Homebrew

Homebrew is a command-line software manager for macOS.

If you have not installed Homebrew before, paste the following into your shell to install it.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Step 3: Install openjdk17

Run the following command in Terminal:

brew install openjdk@17

If the above does not work, then most likely you have a newer Mac machine. In this case, run the following commands instead:

/opt/homebrew/bin/brew shellenv
brew install openjdk@17

To open a Finder Window that points to the current directory, enter the following command in Terminal:

open .

Note the trailing dot at the end. This will be useful when you select your program for submission to CodeCrunch later.

Test Setup Using JShell

In your Unix environment (msys or WSL2) for Windows, or Terminal for MacOS, type jshell at the Unix prompt (denoted as $ below):

$ jshell
|  Welcome to JShell -- Version 17.0.2
|  For an introduction type: /help intro

jshell>

Enter 1 + 1 at the jshell> prompt. It should return 2.

$ jshell
|  Welcome to JShell -- Version 17.0.2
|  For an introduction type: /help intro

jshell> 1 + 1
$1 ==> 2

jshell>

Now type /exit to quit jshell:

$ jshell
|  Welcome to JShell -- Version 17.0.2
|  For an introduction type: /help intro

jshell> 1 + 1
$1 ==> 2

jshell> /exit
|  Goodbye

Here's a tip: if you are interested in the list of JShell commands, you can type /help at the jshell> prompt.

Clone this wiki locally