Close full mode

Install Java on WSL2

Git RepositoryEdit on Github

Install a default version for current Ubuntu WSL2

  • Execute the following commands to install default Java:
    sudo apt update
    sudo apt search jdk
    sudo 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 ~/.bashrc
    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
  • Open a new terminal session and verify if we have set Java home correclty
    java --version

Install Gradle for building Java project

  • Download Gradle to /tmp folder:
    wget -P /tmp
  • Extract zip file to /opt/gradle:
    sudo apt install unzip
    sudo 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
    sudo vi /etc/profile.d/
  • Add the follwing content to
    # /etc/profile.d/
    export GRADLE_HOME=/opt/gradle/gradle-7.3.3
    export PATH=${GRADLE_HOME}/bin:${PATH}
  • Make the script executable:
    sudo chmod +x /etc/profile.d/
  • Load the environment variable
    source /etc/profile.d/
  • Verify if Gradle has been installed successfully:
    gradle -v

Install extensions for VS Code

Loading comments...