使用WSL安装&配置&升级Ubuntu

WSL支持Linux版本查看

  • 如果想了解wsl支持哪些Linux操作系统,可以输入命令:wsl --list -o来查看,当前支持版本如下 :
    当前WSL支持Linux系统

WSL安装Ubuntu

  1. 以管理员方式启动Powershell或者Terminal ,运行命令wls --install即可安装默认版本Ubuntu;
  2. 等待安装完成后,按提示输入用户名和密码后,即可使用了;
  3. 登录方法,在powershellterminal中输入wslubuntu即可启动。
PS C:\Users\Lenovo> wsl --install ubuntu-18.04
Installing: Ubuntu 18.04 LTS
Ubuntu 18.04 LTS has been installed.
Launching Ubuntu 18.04 LTS...
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: evan
Enter new UNIX password:
Retype new UNIX password:
The operation completed successfully.
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

从默认Ubuntu升级到最新版本!

当前WSL默认ubuntu版本是22.04版本,如果想要升级到最新的24.04版本LTS,可以按如下方法进行:

  1. 确认Ubuntu安装配置方式:
vi /etc/update-manager/release-upgrades

确保PromptLTS
在这里插入图片描述2. 确保系统当前是最新的:

sudo apt-get update
sudo apt-get upgrade
  1. 开始升级!
sudo do-release-upgrade -d

如果执行上面命令时报如下错误时,可以尝试强行升级:

$ sudo do-release-upgrade
Checking for a new Ubuntu release
Please install all available updates for your release before upgrading.

sudo apt-get dist-upgrade
  1. 升级完成后,输入exit 退出系统;
  2. 在窗口中输入wsl --terminate Ubuntu结束ubuntu运行;
  3. 重新启动Ubuntu:wsl或者ubuntu
  4. 查看系统版本:
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

可以看到系统已经升级成功。

安装多个版本的Ubuntu

安装多个版本时,只需要在安装命令时,带上对应版本系统名称即可,如当前WSL支持如下版本:

PS C:\Users\Lenovo> wsl --list -o
The following is a list of valid distributions that can be installed.
Install using 'wsl.exe --install <Distro>'.

NAME                                   FRIENDLY NAME
Ubuntu                                 Ubuntu
Debian                                 Debian GNU/Linux
kali-linux                             Kali Linux Rolling
Ubuntu-18.04                           Ubuntu 18.04 LTS
Ubuntu-20.04                           Ubuntu 20.04 LTS
Ubuntu-22.04                           Ubuntu 22.04 LTS
Ubuntu-24.04                           Ubuntu 24.04 LTS
OracleLinux_7_9                        Oracle Linux 7.9
OracleLinux_8_7                        Oracle Linux 8.7
OracleLinux_9_1                        Oracle Linux 9.1
openSUSE-Leap-15.5                     openSUSE Leap 15.5
SUSE-Linux-Enterprise-Server-15-SP4    SUSE Linux Enterprise Server 15 SP4
SUSE-Linux-Enterprise-15-SP5           SUSE Linux Enterprise 15 SP5
openSUSE-Tumbleweed                    openSUSE Tumbleweed

比如我们系统当前安装了默认系统Ubuntu,之后又想安装Ubuntu-18.04,则只需要如此安装即可:

wsl --install -d Ubuntu-18.04

随后等待安装完成即可。

列出当前系统中已安装的Linux系统

PS C:\Users\Lenovo> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu          Running         2
  Ubuntu-18.04    Running         2

多个版本系统如何启动?

方法1:在过访问 Windows“开始”菜单并键入已安装的发行版的名称,可以直接打开 Linux 发行版。 例如:“Ubuntu”。 这会在其自己的控制台窗口中打开 Ubuntu;
方法2:在Powershellterminal中输入wsl -d <DistributionName> ,其中替换为对应系统版本即可,如ubuntu-18.04则输入ubuntu-1804即可

卸载系统

  1. 进入系统设置/应用,找到对应Linux安装程序,进行卸载
    卸载已安装Linux2. 此时通过wsl -l -v查看时依旧存在,比如我执行了卸载Ubuntu 18.04版本:
PS C:\Users\Lenovo> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu          Running         2
  Ubuntu-18.04    Stopped         2
  1. 这是因为还虽然系统已经卸载,但是WSL记录信息依旧存在,此时执行反注册命令即可:
PS C:\Users\Lenovo> wsl -unregister ubuntu-18.04
Invalid command line argument: -unregister
Please use 'wsl.exe --help' to get a list of supported arguments.
PS C:\Users\Lenovo> wsl --unregister ubuntu-18.04
Unregistering.
The operation completed successfully.

升级到非LTS版本最新Ubuntu

  1. 如果待升级的Ubuntu不是LTS长期支持版本,但是我们想尝鲜怎么办?其实上面在升级到最新版本LTS时,提到过一个配置文件,如果注意到配置文件顶上注释说明文字,我们只需要修改下配置即可:
sudo vi /etc/update-manager/release-upgrades

Prompt=lts修改成为Prompt=normal后保存。

  1. 开始升级:
sudo apt-get update
sudo apt-get upgrade
sudo do-release-upgrade
  1. 升级完成后输入exit退出系统;
  2. 输入命令wsl --terminate Ubuntu停止系统
  3. 输入命令wsl或者ubuntu即可启动系统,此时系统就会为最新版本的Ubuntu了。

更新Ubuntu24.04源到国内

从Ubuntu24.04开始,源的配置文件发生了变化 :

evan@DESKTOP-9572KKG:~$ cat /etc/apt/sources.list
# Ubuntu sources have moved to the /etc/apt/sources.list.d/ubuntu.sources
# file, which uses the deb822 format. Use deb822-formatted .sources files
# to manage package sources in the /etc/apt/sources.list.d/ directory.
# See the sources.list(5) manual page for details.

根据上面的提示可以知道,新的配置文件移到了/etc/apt/sources.list.d/ls /etc/apt/sources.list.d/可见新的配置文件是:

evan@DESKTOP-9572KKG:~$ ls -l /etc/apt/sources.list.d/
total 4
-rw-r--r-- 1 root root 3016 Jul  1 15:52 ubuntu.sources

打开文件查看下(cat /etc/apt/sources.list.d/ubuntu.sources):

Types: deb
URIs: http://archive.ubuntu.com/ubuntu
Suites: noble noble-updates noble-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

## Ubuntu security updates. Aside from URIs and Suites,
## this should mirror your choices in the previous section.
Types: deb
URIs: http://security.ubuntu.com/ubuntu
Suites: noble-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

就文件内容而言,配置项少多了,也简化了许多,24.04源可以在网上找到一大堆,我们替换下即可。

比如阿里源:

# 阿里云
Types: deb
URIs: http://mirrors.aliyun.com/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

我们可以备份下配置文件(sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak)后,使用命令sudo vi /etc/apt/sources.list.d/ubuntu.sources替换文件内容即可。

参考链接:

  1. https://4sysops.com/archives/upgrade-from-ubuntu-2204-to-2404-lts-on-windows-subsystem-for-linux-wsl2/#rtoc-9
  2. https://learn.microsoft.com/zh-cn/windows/wsl/install
  • 25
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在WSL安装GUI Ubuntu,需要进行以下步骤: 1. 首先,确保您的Windows 10操作系统版本为2004或更高版本,并已启用WSL 2。您可以通过在命令提示符或PowerShell中运行`wsl --list --verbose`来检查WSL版本。 2. 下载并安装适用于Windows 10的Linux内核更新包。您可以从Microsoft的官方GitHub存储库(https://aka.ms/wsl2kernel)下载该更新包。 3. 在Microsoft Store中安装适用于WSLUbuntu发行版。打开Microsoft Store应用程序,搜索"Ubuntu"并选择"Ubuntu"选项。 4. 启动已安装Ubuntu发行版。您可以在开始菜单中找到它,或者在命令提示符或PowerShell中运行`wsl`命令。 5. 在Ubuntu终端中,运行以下命令以更新软件包列表并升级安装的软件包: ``` sudo apt update sudo apt upgrade ``` 6. 安装必要的软件包以支持GUI应用程序: ``` sudo apt install -y dbus-x11 x11-utils x11-apps ``` 7. 在Windows中安装一个X服务器软件,例如VcXsrv(https://sourceforge.net/projects/vcxsrv/)或Xming(https://sourceforge.net/projects/xming/)。按照软件提供的说明进行安装配置。 8. 在Ubuntu终端中,设置DISPLAY环境变量以指向您安装的X服务器。假设您安装了VcXsrv并将其配置使用默认设置,您可以运行以下命令: ``` export DISPLAY=:0 ``` 9. 现在,您可以运行GUI应用程序并将其显示在Windows上。例如,您可以尝试运行`xeyes`命令来启动一个简单的图形应用程序。 请注意,WSL的GUI支持仍然处于实验阶段,可能会遇到一些问题。如果您遇到问题,可以尝试搜索和查看WSL社区的支持论坛以获取更多帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值