1. General
Before I completely forget, I will record the detailed process of installing WSL2 based Ubuntu under Win11. I have to say that WLS2 is now developed by Microsoft more powerful, it is still worth installing and using, I have successfully set up a ROS environment through the WLS2 installation of Ubuntu.
2. Detailed discussion
2.1 Subsystem installation
Search for "Enable or disable Windows features" in the Win11 search bar, and in the "Windows features" dialog box that pops up, check the boxes for "Windows subsystems for Linux" and "Virtual machine platforms", as shown in Figure 1 below. In the pop-up "Windows Features" dialog box, check "Windows subsystems for Linux" and "Virtual machine platforms", as shown in Figure 1 below:
Click the OK button and wait for the Windows changes to complete. After selecting "Restart Now" and re-entering the Win11 system, start Windows PowerShell. note that, in order to avoid permissions issues, all subsequent ways to start Windows PowerShell can be run as an administrator. I'm not sure which ones require administrator privileges and which ones don't, so I'll just run them as administrators.
Enter the following command in Windows PowerShell:
wsl --update
After that the wsl will be updated as shown in Figure 2 below:
Note that if you are using a newer version of Win11, then it should be installed to WSL2 by default, so there is no need to make the switch to the WSL version. If you are still installing WSL1, then you will have to upgrade to WSL2, as the features of WSL1 and WSL2 are not quite the same.
The next step is to install the Ubuntu distribution through the Microsoft Store, you can search for Ubuntu directly in the Microsoft Store, the author here installed Ubuntu 20.04.6 LTS version, as shown in Figure 3 below:
Now that the internet connection to the Microsoft Store should be stable, the download and installation process is relatively stable. Once the installation is complete, you can search for "Ubuntu 20.04.6 LTS" in the system search bar and launch it, as shown in Figure 4 below:
The first time you start the Ubuntu terminal will let you create a username and password, follow the prompts to set up. However, I accidentally closed the terminal during this step, and the consequence is that every time I start the Ubuntu terminal the account will be the root account.
The installation of the entire system went smoothly, and there were no problems such as the need to switch versions, download other terminals, or migrate addresses.
2.2 Resource management
As a rule, the first thing to do after installing Ubuntu is to update and upgrade the package manager, which is necessary for installing dependent libraries or software. Enter the following command in the terminal:
apt-get update
apt-get upgrade
After the author's test, the above command now does not encounter network problems, I do not know if it is because it is WLS. If you can't update, there are two ways to solve the problem, one is to set up a proxy, and the other is to change the source, so I won't discuss it here.
The good thing about using Ubuntu with WLS is the ease of resource management, such as editing the file /etc/apt/ in order to change the source for the package manager as mentioned earlier. But there is no GUI interface, you can only use terminal-based text editors like Vim and nano, which I don't really want to use anyway. But under WLS, if you follow the previous steps to install successfully, you can directly through Win11 comes with a file explorer to access all the files under Ubuntu, as shown in Figure 5 below:
File resources can be accessed and of course opened and edited by Win11's text editor (note the line breaks in Windows and Ubuntu text files). Not only text files, but also any file resources can be copied and moved easily, and regular copy and paste operations can be realized. In fact, file resources can be used without copying, and files between the two systems can be accessed by each other, although some permission issues may need to be resolved.
2.3 GUI interface
2.3.1 WSLg
Now that you are using Ubuntu, of course you still want to install a GUI interface for it. In fact, the latest WLS2 has integrated WSLg technology, which means it can support GUI programs, just install the GUI program and run it. Enter the command in the Ubuntu terminal:
xeyes
You will be able to see the xeyes application window in your Win11 system, as shown in Figure 6 below:
If the xeyes window does not appear, then it may be a problem with the Win11 version, the WSL version is too low or the GPU driver, just update them all. If the xeyes window appears without any problems, it means that you can open Ubuntu's GUI program directly. For example, you can open Ubuntu's file explorer:
thunar
If the prompt is not recognized, install it:
sudo apt-get update
sudo apt-get install thunar
The startup window is shown in Figure 7 below:
It should be said that dual-system resource interoperability coupled with this file explorer should make it easier to solve a lot of problems.
2.3.2 VcXsrv
If you still want an immersive desktop experience, then you need to install the desktop environment. However, this solution is not just a matter of installing the package, it is more similar to a remote desktop connection, and requires the installation of the X server VcXsrv on the Win11 side, which can be used in itsOfficial websiteUp for download.
A shortcut to XLaunch will be generated on the desktop after the download and installation is complete. Just in case, it is better to start XLaunch as an administrator and first configure the display settings as shown in Figure 8 below:
Show the configuration is used to set the Ubuntu desktop as well as the windowing method of the GUI program, in fact, all four methods are actually possible, here is Multiple windows as an example. Click Next to configure how to start the client, as shown in Figure 9 below:
Just keep the default configuration here. Continue to the next step for additional configuration, as shown in Figure 10 below:
Note that Disable access control must be checked here, otherwise you may not be able to start the GUI desktop. Continue to the next step, click "Save configuration" to save the configuration for the next startup. Click "Finish", VcXsrv will start formally, as shown in Figure 11 below:
Be sure to note that VcXsrv launched via the Multiple windows method does not see windows, it is launched in the background and can be seen in the task manager. If you need to reboot for any reason, turn it off in the task manager and make sure there is only one VcXsrv program.
Above is the operation in Win11 terminal, next is the operation in Ubuntu terminal. Again, to avoid problems start the Ubuntu terminal as administrator and use a root account. Install the xfce4 desktop environment using the following command:
sudo apt install xfce4
Configure the remote presentation address with the following command:
export DISPLAY=192.168.31.168:0
Note that the 192.168.31.168 used here should be replaced by the IP address of your Win11 side, localhost or 127.0.0.1 will not work, because for Ubuntu, Win11 side is actually the remote side, you must use the IP address of the Win11 side. This step should be set every time you start your desktop environment, if you are familiar with the Ubuntu environment, you can configure it in the .bashrc file, which can avoid performing this operation every time.
pass (a bill or inspection etc)sudo startxfce4
Start the xfce4 desktop environment as shown in Figure 12 below:
2.3.3 Problems
If you use WSLg or VcXsrv to connect, there are still some problems, the problem with WSLg is that the GUI program does not support high resolution screen, so the text on the GUI is very small, which hurts your eyes, and the problem with VcXsrv is that only desktop environments started in Multiple windows can support GPU/OpenGL. The problem with VcXsrv is that GPU/OpenGL support is only available in desktop environments that are started in Multiple windows, but there is a problem with GUI programs opened in desktop environments that are started in this way, as clicking on the close button in the title bar does not take effect, or dragging the window's position through the title bar is not possible. The other methods shown in Figure 8, such as Fullscreen and One large window, do not have this problem, but do not support GPU/OpenGL.
But then again, it's true that WLS-based Ubuntu is not the optimal solution for GUI programs that use the GPU, and the author here uses theglxinfo | grep "OpenGL"
The OpenGL display only supports up to OpenGL 3.1, not to mention the drivers for other graphics cards. In the future, if you have the chance, you should try a dual system Ubuntu to experience the feeling of a full-blooded Ubuntu.
3. Reference
- Win11 installs WSL2 subsystem and different distributions of Ubuntu
- WS2 install ubuntu + migration + vscode
- Using the GUI on WSL2 with VcXsrv
- What is the silkiest way to set up a graphical desktop in wsl?