首页 > 系统相关 >win11安装ubuntu(by wsl2)

win11安装ubuntu(by wsl2)

时间:2023-09-06 09:48:59浏览次数:40  
标签:0.0 com https ubuntu win11 docker wsl2 focal

欢迎访问我的GitHub

这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos

本机情况

  • 省吃俭用入手了ThinkPad T14,打算装好Linux后作为开发机器使用,本文记录了安装过程,以便将来在新系统上用到
  • 作为参考,机器软硬件情况如下
    在这里插入图片描述
  • 接下来就是安装wsl2的过程,并未为了验证Linux是否正常,还在Linxu下安装了docker

设置

  • 打开设置窗口,进入"应用" -> "可选功能",点击下图中的更多Windows功能
    在这里插入图片描述

  • 勾选下图红框中的两项
    在这里插入图片描述

  • 点击确定后,会提示正在处理
    在这里插入图片描述

  • 提示重启电脑,选择立即重新启动在这里插入图片描述

  • 支持,设置完成,等重启后就能开始安装了,过程很简单,随本文轻松操作即可

安装

  • 重启后,打开Microsoft Store,就是桌面底部下图箭头所指
    在这里插入图片描述
  • 搜索WSL,然后选择适合自己的Linux版本,我这里选择了最新版的Ubuntu
    在这里插入图片描述
  • 点击获取按钮后,开始等待
    在这里插入图片描述
  • 下载完毕后,点击打开按钮后,控制台报错
    在这里插入图片描述
  • 为了解决上述问题,先以管理员身份打开Windows PowerShell
    在这里插入图片描述
  • 输入wsl --update,对WSL进行更新,等待更新完成,如下图
    在这里插入图片描述
  • 此时新装的ubuntu已经进入应用列表,可以直接点击打开
    在这里插入图片描述
  • 按照控制台提示输入账号密码,即完成设置
  • 输入top命令,再输入数字1,即可看到CPU情况,12代酷睿的多核看起来真是开心啊
will@thinkpad:~$ top
top - 23:50:50 up 2 min,  0 users,  load average: 0.00, 0.00, 0.00
Tasks:   5 total,   1 running,   4 sleeping,   0 stopped,   0 zombie
%Cpu0  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu1  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu2  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu3  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu4  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu5  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu6  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu7  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu8  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu9  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu10 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu11 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu12 :  0.0 us,  0.0 sy,  0.0 ni, 99.7 id,  0.3 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu13 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu14 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu15 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :   7797.3 total,   7404.1 free,    283.7 used,    109.5 buff/cache
MiB Swap:   2048.0 total,   2048.0 free,      0.0 used.   7330.0 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
    1 root      20   0    1756   1080   1020 S   0.0   0.0   0:00.01 init
   48 root      20   0    2112    360      0 S   0.0   0.0   0:00.00 init
   49 root      20   0    2112    368      0 S   0.0   0.0   0:00.01 init
   50 will      20   0   10044   5044   3336 S   0.0   0.1   0:00.02 bash
  118 will      20   0   10872   3648   3136 R   0.0   0.0   0:00.01 t
  • 为了后面操作方便,用命令sudo passwd root给root账号设置密码
will@thinkpad:~$ sudo passwd root
New password:
Retype new password:
passwd: password updated successfully

安装docker

  • docker是常用工具,这里列一下安装步骤
  • 执行sudo apt-get update更新
  • 安装必要软件
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
  • 安装GPG key,用于安装服务的信任
sudo mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
  • 添加安装包仓库
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  • 开始安装(最新版)
sudo apt-get update \
&& sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
  • 如果想安装指定版本,可以先查看版本列表:
apt-cache madison docker-ce
  • 可见有多个版本可供选择
docker-ce | 5:20.10.17~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.16~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.15~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.14~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.13~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.12~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.11~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.10~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.9~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.8~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.7~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.6~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.5~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.4~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.3~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.2~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.1~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.0~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:19.03.15~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:19.03.14~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:19.03.13~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:19.03.12~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:19.03.11~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:19.03.10~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:19.03.9~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
  • 安装指定版本的命令如下,请将<VERSION_STRING>替换成您需要的版本
sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io docker-compose-plugin

启动

  • 用命令service docker status查看服务状态,发现未启动
$ service docker status
* Docker is not running
  • 如下,启动后再查看,发现状态正常
$ sudo service docker start
* Starting Docker: docker                                                                                                                                                 [ OK ]
$ service docker status
* Docker is running
  • 查看版本
$ sudo docker version
Client: Docker Engine - Community
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:02:57 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:01:03 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.7
  GitCommit:        0197261a30bf81f1ee8e6a4dd2dea0ef95d67ccb
 runc:
  Version:          1.1.3
  GitCommit:        v1.1.3-0-g6724737
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
  • 经典的hello world可以验证服务是否正常,命令是sudo docker hello-world
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:7d246653d0511db2a6b2e0436cfd0e52ac8c066000264b3ce63331ac66dca625
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
  • 至此,win11安装wsl2成功,并且验证Linux安装docker也能正常工作

欢迎关注博客园:程序员欣宸

学习路上,你不孤单,欣宸原创一路相伴...

标签:0.0,com,https,ubuntu,win11,docker,wsl2,focal
From: https://www.cnblogs.com/bolingcavalry/p/17673526.html

相关文章

  • 在vmware里安装ubuntu的简单过程(具体的见网址)
    在官网选择vmware版本为16,安装后,在vmware里升级到最新版。(这个可以解决蓝屏)在下面的这个文章里下载ubuntu的镜像文件iso,我下载的是16年的,内存为1.6GB,下载的时间用的少一点,有的要4个G,https://blog.csdn.net/m0_45834939/article/details/121386291  (下载ubuntu的iso文件的网......
  • ubuntu20安装opencv4.5.5
     https://github.com/opencv/opencv/releases/tag/4.5.5  https://github.com/opencv/opencv_contrib/releases/tag/4.5.5 ......
  • ubuntu服务器上部署EMQX SLL
    1.    安装MQTT的简易服务器集成环境EMQX$wgethttps://www.emqx.com/zh/downloads/broker/5.1.6/emqx-5.1.6-ubuntu18.04-amd64.deb$sudoaptinstall./emqx-5.1.6-ubuntu18.04-amd64.deb$sudosystemctlstartemqx具体版本下载请访问:www.emqx.com/zh/try?product=bro......
  • 搭建Ubuntu 22.04可视化界面
    执行以下命令,清空缓存,更新您的软件包列表。sudoaptcleanall&&sudoaptupdate执行以下命令,安装桌面环境所需软件包。包括系统面板、窗口管理器、文件浏览器、终端等桌面应用程序。sudoaptinstallgnome-panelgnome-settings-daemonmetacitynautilusgnome-terminal......
  • Smartkit安装Ubuntu OS系统后,执行脚本批量配置网络和更新软件
    #!/bin/bash#---------------------#systeminitconfig#---------------------#enablerootloginsed-i.bak'31a\PermitRootLoginyes'/etc/ssh/sshd_config/etc/init.d/sshrestart#enableofflinehuaweicloudsources.listcat>/etc/apt/s......
  • Ubuntu 20.04 如何安装NVIDIA的驱动?
    我的环境是:Ubuntu20.041.准备初始环境 sudoapt-getupdate #更新软件列表 sudoapt-getinstallg++ #安装必要依赖 sudoapt-getinstallgcc sudoapt-getinstallmake 2.卸载原先驱动 sudoapt-getremove--purgenvidia* #卸载原有所有驱动(或者nvi......
  • 视频监控/安防监控EasyCVR平台智能边缘网关硬件ubuntu系统如何取消休眠?
    安防视频监控/视频集中存储/云存储/磁盘阵列EasyCVR平台可拓展性强、视频能力灵活、部署轻快,可支持的主流标准协议有国标GB28181、RTSP/Onvif、RTMP等,以及支持厂家私有协议与SDK接入,包括海康Ehome、海大宇等设备的SDK等。视频汇聚融合管理平台EasyCVR既具备传统安防视频监控的能力,......
  • Ubuntu截屏工具推荐
    Ubuntu截屏工具推荐本篇博文推荐Ubuntu下的截屏工具Flameshot,可以作为Windows下Snipaste截图工具的平替。GitHub地址:https://github.com/flameshot-org/flameshot安装sudoaptupdatesudoaptinstallflameshot快捷键截图贴图安装之后点击应用图标就可以截图了,下面介绍......
  • ubuntu 22.04 安装docker-ce
    #!/bin/bash##安装依赖sudoapt-getupdatesudoapt-get-yinstallapt-transport-httpsca-certificatescurlsoftware-properties-common##安装GPG证书curl-fsSLhttps://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg|sudoapt-keyadd-##写入软件源信息sudoa......
  • Ubuntu 20.04 部署笔记
    一键dd脚本脚本内容及安全性笔者不作保证,请自行判断https://github.com/fcurrk/reinstall/tree/masterapt换源如果服务器在国内,可以考虑换源,下面是清华源 https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/sudovim/etc/apt/sources.list替换文件内容为以下内容#......