Setting up Unix for Java Development - nus-cs2030/2324-s2 GitHub Wiki
Depending on whether you are using a Windows or Mac machine, choose ONE of the following set-ups:
- Setup for Windows (through Scoop & mSys)
- Setup for Windows (through Windows Subsystem for Linux)
- Setup for Mac
Then test your setup with jshell
:
- Hit ⊞ Win to open the Start menu, type
PowerShell
and press Enter.
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.
Run the following command in the PowerShell window:
scoop install git
scoop install msys
If msys fails to complete its installation, you may instead try
scoop install main/msys
Run the following commands in the PowerShell window one at a time:
scoop bucket add java
scoop install openjdk17
After all installation is completed, hit ⊞ Win to open the Start menu, type msys
and press enter.
Alternatively, you may navigate to the folder
C\Users\your_userid\scoop\apps\msys\current
and click on
msys.bat
.
If you are still not able to successfully execute msys.bat
, it
would most likely be due to your current userid containing spaces.
You will need to create another userid with no spaces as an "alias"
to the current one. In the search bar, type cmd
, right click
the Command Prompt
app and select Run as administrator
.
Within the Command Prompt window, type and execute the following commands one after another.
c:
cd c:\Users
mklink /j myalias "User Id With Space"
You may replace myalias
with any name that does not contain spaces.
This will become the userid you use to navigate to msys.bat
.
Once inside the msys window, enter the following command.
echo "PATH=/c/Users/your_userid/scoop/apps/openjdk17/current/bin/:\$PATH" >> ~/.profile
source ~/.profile
The above is to ensure that msys points to the correct jdk. YOU NEED ONLY DO THIS ONCE.
To open a File Explorer Window that points to the current directory, enter the following command in msys:
explorer.exe .
Note the trailing dot at the end. This will be useful when you select your program for submission to CodeCrunch later.
If you encounter problems with installing through Scoop and mSys, you may try to set-up a Unix environment through the Windows Subsystem for Linux (WSL) application.
Open any command-line interface (e.g. cmd
or PowerShell
) and enter this following command:
wsl --install
Alternatively, you can download WSL from the Microsoft Store here
After WSL has been installed, you will be prompted for a new UNIX username. It is OK if you do not key anything in.
After set-up is complete, type in this following command:
sudo apt install openjdk-17-jdk-headless
Once prompted, type Y
and it will start installing.
As the default editor is not installed within WSL, you will encounter problems if you execute /edit
without changing the default editor.
1: Execute jshell
.
2: Enter this command: \set editor -retain vim
, you can replace vim with any other pre-installed Unix text editors (like emacs)
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 .
Run the following command within Terminal to install a set of command-line tools used for software development in macOS.
xcode-select --install
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)"
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.
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.