Install Java on WSL2
Install a default version for current Ubuntu WSL2
- Execute the following commands to install default Java:sudo apt updatesudo apt search jdksudo apt install default-jdk
- Alternatively, if you want to install a specific version, sepecify a package as the following command:sudo apt install openjdk-8-jdk
Set Java home
- Edit .bashrc file to export JAVA_HOME variable:sudo vi ~/.bashrcexport JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
- Open a new terminal session and verify if we have set Java home correcltyjava --version
Install Gradle for building Java project
- Download Gradle to
/tmp
folder:wget https://services.gradle.org/distributions/gradle-7.3.3-bin.zip -P /tmp - Extract zip file to
/opt/gradle
:sudo apt install unzipsudo unzip -d /opt/gradle /tmp/gradle-*.zip- Verify Gradle files
ls /opt/gradle/gradle-7.3.3/ - You should see some Gradle files.
- Set up environment variable by creating gradle.sh:sudo vi /etc/profile.d/gradle.sh
- Add the follwing content to gradle.sh# /etc/profile.d/gradle.shexport GRADLE_HOME=/opt/gradle/gradle-7.3.3export PATH=${GRADLE_HOME}/bin:${PATH}
- Make the script executable:sudo chmod +x /etc/profile.d/gradle.sh
- Load the environment variablesource /etc/profile.d/gradle.sh
- Verify if Gradle has been installed successfully:gradle -v
Install extensions for VS Code
Credit & Useful links
Loading comments...