Setting Up Ubuntu WSL
- Installing WSL and Ubuntu
To begin, enable Windows Subsystem for Linux through the Windows Control Panel:
- Navigate to "Control Panel" → "Programs" → "Turn Windows features on or off"
- Ensure "Windows Subsystem for Linux" is checked
After enabling WSL, install Ubuntu from the Microsoft Store.
- Root Access
Upon first login, you'll need to set a root password:
sudo passwd
Once set, use the following command to switch to root user:
su root
- File Access
For users less familiar with Linux commands, you can access WSL files through Windows Explorer:
- In File Explorer, enter
\\wsl$in the address bar - Consider pinning this location to Quick Access for convenience
- Configuring Domestic Repository
To improve download speeds, configure Ubuntu to use a domestic repository. This example uses Alibaba Cloud's mirror:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
Edit the sources.list file with the following content:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
Update the package repository:
sudo apt-get update
Acquiring OpenJDK 12 Source Code
The official OpenJDK 12 source repository is available at:
http://hg.openjdk.java.net/jdk/jdk12/file/06222165c35f
Preparing the Build Environment
- Documentation
After downloading and extracting the source code, refer to the documentation in the doc directory for build instructions.
- Installing Build Tools
Install the essential build tools:
sudo apt-get install build-essential
- Installing Required Libraries
The following dependencies are necessary for a successful build:
| Tool | Library Name | Installation Command |
|---|---|---|
| FreeType | The Free Type Project | sudo apt-get install libfreetype6-dev |
| CUPS | Common UNIX Printing System | sudo apt-get install libcups2-dev |
| X11 | X Window System | sudo apt-get install libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev |
| ALSA | Advanced Linux Sound Architecture | sudo apt-get install libasound2-dev |
| libffi | Portable Foreign Function Interface Library | sudo apt-get install libffi-dev |
| Autoconf | Extensible Package of M4 Macros | sudo apt-get install autoconf |
- Installing Java 11
A Java 11 JDK is required as the boot JDK:
sudo apt-get install openjdk-11-jdk
- Installing ZIP Utility
The ZIP utility is required during the build process:
sudo apt-get install zip
Without ZIP, you may encounter the following error during configuration:
configure: error: Could not find required tool for ZIPEXE
configure exiting with result code 1
Compiling OpenJDK 12
- Configuration
Configure the build with your desired parameters. For example, to build a FastDebug version with only the Server JVM variant:
bash configure --enable-debug --with-jvm-variants=server
If the anvironment is proper configured, you'll see a summary similar to this:
====================================================
A new configuration has been successfully created in
/home/developer/jdk12/build/linux-x86_64-server-fastdebug
using configure arguments '--enable-debug --with-jvm-variants=server'.
Configuration summary:
* Debug level: fastdebug
* HS debug level: fastdebug
* JVM variants: server
* JVM features: server: 'aot cds cmsgc compiler1 compiler2 epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs zgc'
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64
* Version string: 12-internal+0-adhoc.dev.jdk12 (12-internal)
Tools summary:
* Boot JDK: openjdk version "11.0.6" 2020-01-14 OpenJDK Runtime Environment (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1) OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1, mixed mode, sharing) (at /usr/lib/jvm/java-11-openjdk-amd64)
* Toolchain: gcc (GNU Compiler Collection)
* C Compiler: Version 7.5.0 (at /usr/bin/gcc)
* C++ Compiler: Version 7.5.0 (at /usr/bin/g++)
Build performance summary:
* Cores to use: 4
* Memory limit: 12154 MB
This creates a build directory at the specified path.
- Building
Execute the build command:
make images
The resulting JDK will be available in the build directory.
Using the Compiled JDK
- Setting Environment Variables
Configure your environment to use the newly built JDK by editing your bash profile:
sudo vim ~/.bashrc
Add the following lines at the end of the file:
export JAVA_HOME=/home/developer/jdk12/build/linux-x86_64-server-fastdebug/jdk
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
Apply the changes:
source ~/.bashrc
Verify the installation:
$ java -version
openjdk version "12-internal" 2019-03-19
OpenJDK Runtime Environment (fastdebug build 12-internal+0-adhoc.dev.jdk12)
OpenJDK 64-Bit Server VM (fastdebug build 12-internal+0-adhoc.dev.jdk12, mixed mode)
- Testing the Installation
Create a simple test program:
cat > TestApp.java <<EOF
public class TestApp {
public static void main(String[] args) {
System.out.println("Hello from OpenJDK 12");
}
}
EOF
Compile and run the test:
javac TestApp.java
java TestApp
Expected output:
Hello from OpenJDK 12