ToB企服应用市场:ToB评测及商务社交产业平台
标题:
使用WSL安装&配置&升级Ubuntu
[打印本页]
作者:
慢吞云雾缓吐愁
时间:
2024-8-10 02:52
标题:
使用WSL安装&配置&升级Ubuntu
WSL支持Linux版本检察
如果想相识wsl支持哪些Linux操纵系统,可以输入命令:wsl --list -o来检察,当前支持版本如下 :
WSL安装Ubuntu
以管理员方式启动Powershell或者Terminal ,运行命令wls --install即可安装默认版本Ubuntu;
等待安装完成后,按提示输入用户名和暗码后,即可使用了;
登录方法,在powershell或terminal中输入wsl或ubuntu即可启动。
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,可以按如下方法进行:
确认Ubuntu安装配置方式:
vi /etc/update-manager/release-upgrades
复制代码
确保Prompt 为LTS:
2. 确保系统当前是最新的:
sudo apt-get update
sudo apt-get upgrade
复制代码
开始升级!
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
复制代码
升级完成后,输入exit 退出系统;
在窗口中输入wsl --terminate Ubuntu结束ubuntu运行;
重新启动Ubuntu:wsl或者ubuntu
检察系统版本:
$ 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:在Powershell或terminal中输入wsl -d <DistributionName> ,此中更换为对应系统版本即可,如ubuntu-18.04则输入ubuntu-1804即可
卸载系统
进入系统设置/应用,找到对应Linux安装步调,进行卸载
2. 此时通过wsl -l -v检察时依旧存在,比如我实行了卸载Ubuntu 18.04版本:
PS C:\Users\Lenovo> wsl -l -v
NAME STATE VERSION
* Ubuntu Running 2
Ubuntu-18.04 Stopped 2
复制代码
这是因为还虽然系统已经卸载,但是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
如果待升级的Ubuntu不是LTS长期支持版本,但是我们想尝鲜怎么办?其实上面在升级到最新版本LTS时,提到过一个配置文件,如果注意到配置文件顶上解释说明文字,我们只必要修改下配置即可:
sudo vi /etc/update-manager/release-upgrades
复制代码
把Prompt=lts修改成为Prompt=normal后保存。
开始升级:
sudo apt-get update
sudo apt-get upgrade
sudo do-release-upgrade
复制代码
升级完成后输入exit退出系统;
输入命令wsl --terminate Ubuntu停止系统
输入命令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更换文件内容即可。
参考链接:
https://4sysops.com/archives/upgrade-from-ubuntu-2204-to-2404-lts-on-windows-subsystem-for-linux-wsl2/#rtoc-9
https://learn.microsoft.com/zh-cn/windows/wsl/install
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/)
Powered by Discuz! X3.4