Motivation
and Java in Visual Studio Code and see the reason I choose WSL instead of Windows.
As required by the course, I will install Java 8., which is a LTS version.
There are many distributed versions of JDK. For convenience, I will choose to install directly from
apt
Steps
- (Optional) Ensures that you have the latest packages in WSL
sudo apt update && sudo apt upgrade
- Verifying the availability of OpenJDK
apt-cache search openjdk-8 | grep openjdk-8
Note
jre
is short for Java Runtime Environment, while jdk
is for Java Development Kit.- Install OpenJDK 8
sudo apt install openjdk-8-jdk
This command line will also install
openjdk-8-jre
automatically. So no bother to do it manually.- Verify the installation
java -version
If you are installing Java 9+,
java --version
also worksIf something goes wrong, use
which java
to determine if you are using the java just installed, or you are actually using other version installed previously (as below):Write the following lines into
~/.bashrc
to prepend the Java of desired version to PATH
.export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/" export PATH="$JAVA_HOME/bin:$PATH"
Don’t forget to run
source ~/.bashrc
to activate the added setting.- (Optional) Configure runtime version and path
In VScode, use
Ctrl+Shift+P
to open the Command Palette, search for Preference: Open Remote Settings (JSON) (WSL)
and append the configuration below{ // other configurations ..., "java.configuration.runtimes": [ { "name": "JavaSE-1.8", "path": "/usr/lib/jvm/java-8-openjdk-amd64", "default": true }, { "name": "JavaSE-11", "path": "/usr/lib/jvm/java-11-openjdk-amd64", }, { "name": "JavaSE-13", "path": "/usr/lib/jvm/java-13-openjdk-amd64", }, ] }
You can set one of them to default by adding
"default": true
to the entry.
To see which JDKs are used for your projects, you can trigger the command Java: Configure Java Runtime in Command Palette (Ctrl+Shift+P
).Done 👏
Use jenv
to manage java version
Setup Java on windows
winget search jdk winget install Oracle.JDK.21
Download Maven here, e.g.,
apache-maven-3.9.6-bin.zip
unzip the
zip
file, add /bin
to environment variables.