Linux - WSL

Helpful tips about using WSL

How can I check if Virtualization is enabled/disabled on my desktop/laptop?

https://support.bluestacks.com/hc/en-us/articles/360058102252-How-to-enable-Virtualization-VT-on-Windows-10-for-BlueStacks-5

  1. Open Task Manager and go to “Performance” tab and under CPU, you will find information about Virtualization on your desktop/laptop.
  2. If it says Enabled, then Virtualization is turned on.
  3. However, if it says Disabled, then Virtualization is turned off.

How to explore WSL distribution’s file system using Windows File Explorer?

  1. Go to terminal in the WSL distribution and run this command explorer.exe .
  2. 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

  1. Multiple terminal emulator like ConEmu (Windows 11 comes with the latest terminal with support for multiple tabs)
  2. With the latest versions of Windows, Command Prompt comes with support for tabs

Helpful tools to install in WSL

  1. fix bashrc set-up
  2. neofetch
  3. emacs
  4. fix org-roam set-up
  5. browser
  6. ripgrep
  7. jdk
  8. 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?

https://stackoverflow.com/questions/63866813/what-is-the-proper-way-of-using-jdk-on-wsl2-on-windows-10

There are two ways to do this.

  1. Use the jdk installation from the host Windows machine
  2. Install jdk on the WSL OS

Using the jdk from the host Windows machine

Step 1:

  1. Add java variable to path (/etc/environment)
  2. Run sudo vim /etc/environment
  3. It would open a buffer that should have only a PATH="…" variable.
  4. Then paste the code below in a new line:
    JAVA_HOME=/mnt/c/Program Files/Java/jdk-<YOUR-VERSION>
    
    To check your version, navigate from your ubuntu terminal to mnt/c/Program Files/Java
    $ cd /mnt/c/"Program Files"/Java/
    
    Then run ls, you would see the version available. See how below:
    /mnt/c/Program Files/Java$: ls
    jdk-21.0.5 //YOUR VERSION
    

Step 2:

  1. 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:

  1. Run java.exe
  2. If you run this, it would fail. But it is good sign.
  3. Now, append the java variable to your path.
    PATH="...bin:/mnt/c/Program Files/Java/jdk-<YOUR-VERSION>/bin"
    
  4. Save and exit the buffer
  5. Do not forget to add : between bin and /mnt
  6. source /etc/environment

Step 4:

  1. Now run java.exe --version
  2. You should see your version
  3. Add alias if you want in your ~/.bashrc:
    alias java='java.exe'
    alias javac='javac.exe'
    
  4. 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

Links to this note