ToB企服应用市场:ToB评测及商务社交产业平台

标题: 使用WSL安装&配置&升级Ubuntu [打印本页]

作者: 慢吞云雾缓吐愁    时间: 2024-8-10 02:52
标题: 使用WSL安装&配置&升级Ubuntu
WSL支持Linux版本检察


WSL安装Ubuntu

  1. PS C:\Users\Lenovo> wsl --install ubuntu-18.04
  2. Installing: Ubuntu 18.04 LTS
  3. Ubuntu 18.04 LTS has been installed.
  4. Launching Ubuntu 18.04 LTS...
  5. Installing, this may take a few minutes...
  6. Please create a default UNIX user account. The username does not need to match your Windows username.
  7. For more information visit: https://aka.ms/wslusers
  8. Enter new UNIX username: evan
  9. Enter new UNIX password:
  10. Retype new UNIX password:
  11. The operation completed successfully.
  12. Installation successful!
  13. To run a command as administrator (user "root"), use "sudo <command>".
  14. See "man sudo_root" for details.
复制代码
从默认Ubuntu升级到最新版本!

当前WSL默认ubuntu版本是22.04版本,如果想要升级到最新的24.04版本LTS,可以按如下方法进行:
  1. vi /etc/update-manager/release-upgrades
复制代码
确保Prompt 为LTS:
2. 确保系统当前是最新的:
  1. sudo apt-get update
  2. sudo apt-get upgrade
复制代码
  1. sudo do-release-upgrade -d
复制代码
如果实行上面命令时报如下错误时,可以实验强行升级:
  1. $ sudo do-release-upgrade
  2. Checking for a new Ubuntu release
  3. Please install all available updates for your release before upgrading.
  4. sudo apt-get dist-upgrade
复制代码
  1. $ cat /etc/os-release
  2. PRETTY_NAME="Ubuntu 24.04 LTS"
  3. NAME="Ubuntu"
  4. VERSION_ID="24.04"
  5. VERSION="24.04 LTS (Noble Numbat)"
  6. VERSION_CODENAME=noble
  7. ID=ubuntu
  8. ID_LIKE=debian
  9. HOME_URL="https://www.ubuntu.com/"
  10. SUPPORT_URL="https://help.ubuntu.com/"
  11. BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
  12. PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
  13. UBUNTU_CODENAME=noble
  14. LOGO=ubuntu-logo
复制代码
可以看到系统已经升级成功。
安装多个版本的Ubuntu

安装多个版本时,只必要在安装命令时,带上对应版本系统名称即可,如当前WSL支持如下版本:
  1. PS C:\Users\Lenovo> wsl --list -o
  2. The following is a list of valid distributions that can be installed.
  3. Install using 'wsl.exe --install <Distro>'.
  4. NAME                                   FRIENDLY NAME
  5. Ubuntu                                 Ubuntu
  6. Debian                                 Debian GNU/Linux
  7. kali-linux                             Kali Linux Rolling
  8. Ubuntu-18.04                           Ubuntu 18.04 LTS
  9. Ubuntu-20.04                           Ubuntu 20.04 LTS
  10. Ubuntu-22.04                           Ubuntu 22.04 LTS
  11. Ubuntu-24.04                           Ubuntu 24.04 LTS
  12. OracleLinux_7_9                        Oracle Linux 7.9
  13. OracleLinux_8_7                        Oracle Linux 8.7
  14. OracleLinux_9_1                        Oracle Linux 9.1
  15. openSUSE-Leap-15.5                     openSUSE Leap 15.5
  16. SUSE-Linux-Enterprise-Server-15-SP4    SUSE Linux Enterprise Server 15 SP4
  17. SUSE-Linux-Enterprise-15-SP5           SUSE Linux Enterprise 15 SP5
  18. openSUSE-Tumbleweed                    openSUSE Tumbleweed
复制代码
比如我们系统当前安装了默认系统Ubuntu,之后又想安装Ubuntu-18.04,则只必要如此安装即可:
  1. wsl --install -d Ubuntu-18.04
复制代码
随后等待安装完成即可。
列出当前系统中已安装的Linux系统

  1. PS C:\Users\Lenovo> wsl -l -v
  2.   NAME            STATE           VERSION
  3. * Ubuntu          Running         2
  4.   Ubuntu-18.04    Running         2
复制代码
多个版本系统怎样启动?

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

  1. PS C:\Users\Lenovo> wsl -l -v
  2.   NAME            STATE           VERSION
  3. * Ubuntu          Running         2
  4.   Ubuntu-18.04    Stopped         2
复制代码
  1. PS C:\Users\Lenovo> wsl -unregister ubuntu-18.04
  2. Invalid command line argument: -unregister
  3. Please use 'wsl.exe --help' to get a list of supported arguments.
  4. PS C:\Users\Lenovo> wsl --unregister ubuntu-18.04
  5. Unregistering.
  6. The operation completed successfully.
复制代码
升级到非LTS版本最新Ubuntu

  1. sudo vi /etc/update-manager/release-upgrades
复制代码
把Prompt=lts修改成为Prompt=normal后保存。
  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo do-release-upgrade
复制代码
更新Ubuntu24.04源到国内

从Ubuntu24.04开始,源的配置文件发生了变化 :
  1. evan@DESKTOP-9572KKG:~$ cat /etc/apt/sources.list
  2. # Ubuntu sources have moved to the /etc/apt/sources.list.d/ubuntu.sources
  3. # file, which uses the deb822 format. Use deb822-formatted .sources files
  4. # to manage package sources in the /etc/apt/sources.list.d/ directory.
  5. # See the sources.list(5) manual page for details.
复制代码
根据上面的提示可以知道,新的配置文件移到了/etc/apt/sources.list.d/,ls /etc/apt/sources.list.d/可见新的配置文件是:
  1. evan@DESKTOP-9572KKG:~$ ls -l /etc/apt/sources.list.d/
  2. total 4
  3. -rw-r--r-- 1 root root 3016 Jul  1 15:52 ubuntu.sources
复制代码
打开文件检察下(cat /etc/apt/sources.list.d/ubuntu.sources):
  1. Types: deb
  2. URIs: http://archive.ubuntu.com/ubuntu
  3. Suites: noble noble-updates noble-backports
  4. Components: main universe restricted multiverse
  5. Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
  6. ## Ubuntu security updates. Aside from URIs and Suites,
  7. ## this should mirror your choices in the previous section.
  8. Types: deb
  9. URIs: http://security.ubuntu.com/ubuntu
  10. Suites: noble-security
  11. Components: main universe restricted multiverse
  12. Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
复制代码
就文件内容而言,配置项少多了,也简化了许多,24.04源可以在网上找到一大堆,我们更换下即可。
比如阿里源:
  1. # 阿里云
  2. Types: deb
  3. URIs: http://mirrors.aliyun.com/ubuntu/
  4. Suites: noble noble-updates noble-security
  5. Components: main restricted universe multiverse
  6. 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更换文件内容即可。
参考链接:


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4