Linux - WSL
Table of Contents
- Helpful tips about using WSL
- How can I check if Virtualization is enabled/disabled on my desktop/laptop?
- How to explore WSL distribution’s file system using Windows File Explorer?
- Helpful WSL commands
- Helpful tools to install in the host windows machine
- Helpful tools to install in WSL
- Running IntelliJ
- How to install JDK on WSL2?
Helpful tips about using WSL
How can I check if Virtualization is enabled/disabled on my desktop/laptop?
- Open Task Manager and go to “Performance” tab and under CPU, you will find information about Virtualization on your desktop/laptop.
- If it says Enabled, then Virtualization is turned on.
- However, if it says Disabled, then Virtualization is turned off.
How to explore WSL distribution’s file system using Windows File Explorer?
- Go to terminal in the WSL distribution and run this command
explorer.exe . - The dot represents “current directory”.
Helpful WSL commands
https://learn.microsoft.com/en-us/windows/wsl/install
| Command | Description |
|---|---|
| wsl –set-default-version 2 | Set wsl version to 2 |
| wsl –list –online | To see a list of available Linux distributions available for download through the online store |
| wsl –install -d <Distribution Name> | To install a specific distro |
| wsl –list –verbose or wsl -l -v | Check existing distros in your Windows computer that work with WSL |
| wsl –set-default ubuntu-docker or wsl -S ubuntu-docker | Make a specific instance the default distro for WSL |
| wsl | Run a new default wsl |
| wsl –unregister DISTRO-NAME or wsl –unregister Ubuntu | Remove imported Linux distro on WSL with commands |
| wsl –terminate <Distribution Name> or wsl -t <Distribution Name> | Stop running instances |
| wsl –shutdown | To shutdown the current running distro |
Helpful tools to install in the host windows machine
- Multiple terminal emulator like ConEmu (Windows 11 comes with the latest terminal with support for multiple tabs)
- With the latest versions of Windows, Command Prompt comes with support for tabs
Helpful tools to install in WSL
- fix bashrc set-up
- neofetch
- emacs
- fix org-roam set-up
- browser
- ripgrep
- jdk
- maven
Running IntelliJ
I got this error when I wanted to run the intellij-idea-community for the first time:
CompileCommand: exclude com/intellij/openapi/vfs/impl/FilePartNodeRoot.trieDescend bool exclude = true
Start Failed
Internal error. Please refer to https://jb.gg/ide/critical-startup-errors
java.lang.NoClassDefFoundError: Could not initialize class java.awt.Toolkit
at java.desktop/java.awt.Color.<clinit>(Color.java:277)
at com.intellij.ide.ui.laf.IdeaLaf.<clinit>(IdeaLaf.java:24)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at com.intellij.idea.StartupUtil$preloadLafClasses$1.invokeSuspend(StartupUtil.kt:579)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Suppressed: java.lang.UnsatisfiedLinkError: /snap/intellij-idea-community/409/jbr/lib/libawt_xawt.so: libXrender.so.1: cannot open shared object file: No such file or directory
at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2389)
at java.base/java.lang.Runtime.load0(Runtime.java:755)
at java.base/java.lang.System.load(System.java:1953)
at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
at java.base/jdk.internal.loader.NativeLibraries.findFromPaths(NativeLibraries.java:315)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:285)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2398)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
at java.base/java.lang.System.loadLibrary(System.java:1989)
at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:1388)
at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:1386)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at java.desktop/java.awt.Toolkit.loadLibraries(Toolkit.java:1385)
at java.desktop/java.awt.Toolkit.initStatic(Toolkit.java:1428)
at java.desktop/java.awt.Toolkit.<clinit>(Toolkit.java:1397)
at com.intellij.idea.StartupUtil$initAwtToolkit$1$1.invokeSuspend(StartupUtil.kt:485)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
... 4 more
-----
Your JRE: 17.0.5+1-b653.25 amd64 (JetBrains s.r.o.)
/snap/intellij-idea-community/409/jbr
Also, a UI exception occurred on an attempt to show the above message
java.lang.NoClassDefFoundError: Could not initialize class java.awt.Toolkit
at java.desktop/java.awt.Component.<clinit>(Component.java:632)
at com.intellij.idea.StartupErrorReporter.showMessage(StartupErrorReporter.java:85)
at com.intellij.idea.StartupErrorReporter.showMessage(StartupErrorReporter.java:39)
at com.intellij.idea.Main.main(Main.kt:65)
After installing gnome-software, like gnome-system-monitor that has some dependencies on X11-related packages, everything is fixed!
How to install JDK on WSL2?
There are two ways to do this.
- Use the jdk installation from the host Windows machine
- Install jdk on the WSL OS
Using the jdk from the host Windows machine
Step 1:
- Add java variable to path (/etc/environment)
- Run sudo vim /etc/environment
- It would open a buffer that should have only a PATH="…" variable.
- Then paste the code below in a new line:
To check your version, navigate from your ubuntu terminal to mnt/c/Program Files/JavaJAVA_HOME=/mnt/c/Program Files/Java/jdk-<YOUR-VERSION>
Then run ls, you would see the version available. See how below:$ cd /mnt/c/"Program Files"/Java//mnt/c/Program Files/Java$: ls jdk-21.0.5 //YOUR VERSION
Step 2:
- On the same terminal after adding JAVA_HOME to etc/envrironment, run
$ source /etc/environment $ echo $JAVA_HOME // this should return what you had in your etc/environment
Step 3:
- Run java.exe
- If you run this, it would fail. But it is good sign.
- Now, append the java variable to your path.
PATH="...bin:/mnt/c/Program Files/Java/jdk-<YOUR-VERSION>/bin" - Save and exit the buffer
- Do not forget to add
:between bin and /mnt source /etc/environment
Step 4:
- Now run
java.exe --version - You should see your version
- Add alias if you want in your ~/.bashrc:
alias java='java.exe' alias javac='javac.exe' - Lastly If you leave your terminal and restart. But java –version or java.exe –version do not work, ensure JAVA_HOME is always available, add this to your shell config:
$ echo 'export JAVA_HOME="/mnt/c/Program Files/Java/jdk-21.0.5"' >> ~/.bashrc $ echo 'export PATH="$JAVA_HOME/bin:$PATH"' >> ~/.bashrc $ source ~/.bashrc
Install jdk on the WSL OS
$ sudo apt update
$ sudo apt install openjdk-11-jdk
Once the installation is complete, you can verify it by checking the Java version:
$ java -version