WSL2 安装GNOME桌面 ubuntu20.04

本文提供了一种教程,指导用户如何在Windows子系统Linux(WSL2)上安装和配置GNOME桌面环境,包括所需的前提条件、安装步骤和解决启动时可能遇到的问题。通过启用systemd并使用Xserver,如VcXsrv,用户可以在WSL2上获得完整的Linux桌面体验。
摘要由CSDN通过智能技术生成

WSL 2 GNOME Desktop

NOTE: If you want the ultimate Linux desktop experience, I highly recommend installing Linux as your main OS. I no longer use Windows (except in a VM) so I will not be maintaining this guide anymore.

Think Xfce looks dated? Want a conventional Ubuntu experience? This tutorial will guide you through installing Ubuntu's default desktop environment, GNOME.

GNOME is one of the more complex — and that means more difficult to run — desktop environments, so for years people couldn't figure out how to run it on WSL 2. On WSL 1 it could only run using very complicated methods that didn't transfer to well WSL 2. Any forlorn attempts to run it on WSL 2 only resulted in a smoldering heap of error messages.

But now you can!

Requirements:

  • WSL 2
  • Ubuntu 20.04 (other distros not tested)
  • An X server for Windows, such as VcXsrv
  • Basic knowledege on how to run GUI apps with WSL 2 (not required but highly recommended)

Getting ready

You've been regularly updating your distro, haven't you?

sudo apt update
sudo apt upgrade

Install GNOME: (maybe go eat a snack while it's installing?)

sudo apt install ubuntu-desktop gnome

Open up your ~/.bashrc:

nano ~/.bashrc

And paste this in at the end:

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
export LIBGL_ALWAYS_INDIRECT=1

and save:

在nano编辑器中输入或粘贴你要添加到文件~/.bashrc的内容,然后按下键盘上的“Ctrl”键和“O”键保存更改。在弹出的选项中确认文件名无误后按下“Enter”键。之后按下键盘上的“Ctrl”键和“X”键退出nano编辑器。

If you try to start GNOME now, you'll get a lot of errors. Something along the lines of this, but a ton more errors:

Unable to init server: Could not connect: Connection refused

(gnome-session-check-accelerated:6054): Gtk-WARNING **: 11:04:51.973: cannot open display: :0
Unable to init server: Could not connect: Connection refused

(gnome-session-check-accelerated:6055): Gtk-WARNING **: 11:04:52.234: cannot open display: :0
gnome-session-binary[6044]: WARNING: software acceleration check failed: Child process exited with code 1
gnome-session-binary[6044]: CRITICAL: We failed, but the fail whale is dead. Sorry....

The trick is to enable systemd: (note that this does break a lot of stuff such as Visual Studio Code Remote)

git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
bash ubuntu-wsl2-systemd-script.sh

Now shut down WSL 2: (run this in Windows)

wsl --shutdown

Starting GNOME

First, fire up your X server on Windows. Make sure you let it through your firewall and disable access control.

Now, start up Ubuntu again and start GNOME:

gnome-session

If you don't get any error messages, you should be good. Wait a few seconds for GNOME to start up.

Now you have a great GUI desktop and you won't need any intensive virtual machines anymore!

Profit?

Notes

  • You can disable the screensaver with gsettings set org.gnome.desktop.session idle-delay 0.
  • You can also try KDE Plamsa using a similar method! Just sudo apt install kde-plasma-desktop instead and start it with startplasma-x11.

Troubleshooting

If you can't get this to work, try Xfce.

If you still can't get it to work, you can ask for help on an online forum such as r/bashonubuntuonwindows.

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值