window10 powsershell 安装ubuntu22.04

 参考  https://learn.microsoft.com/en-us/windows/wsl/basic-commands#install

          https://learn.microsoft.com/en-us/windows/wsl/install

 List available Linux distributions  

wsl --list --online

以下是可安装的有效分发的列表。
使默认分发用 “*” 表示。
使用 'wsl --install -d <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
.......

List installed Linux distributions

wsl --list --verbose

 安装

若安装默认版本,则仅仅执行“wsl --install”,如果想安装指定版本,比如打算装“Ubuntu-22.04”,则执行

wsl --install -d Ubuntu-22.04

正在安装: 适用于 Linux 的 Windows 子系统
已安装 适用于 Linux 的 Windows 子系统。
正在安装: Ubuntu 22.04 LTS
已安装 Ubuntu 22.04 LTS。
请求的操作成功。直到重新启动系统前更改将不会生效。

重启机器后弹出窗口,在该窗口中提示需要设置用户名和密码

Ubuntu 22.04 LTS 已安装。
正在启动 Ubuntu 22.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: ubuntu
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".

之后安装必要的库,然后就可以开始正式的编程工作了

sudo apt-get update
sudo apt install build-essential
sudo apt install zlib1g-dev libevent-dev

 Shutdown

wsl --shutdown

Terminate

wsl --terminate <Distribution Name>

卸载

wsl uninstall

 

注1: 若重启后安装界面提示“Wsl/Service/CreateInstance/MountVhd/ERROR_FILE_NOT_FOUND”

      该原因为之前安装过但又卸载了,可以参照 https://superuser.com/questions/1758361/error-code-wsl-service-createinstance-mountvhd-error-file-not-found

From the WSL Github issue on the topic and the resulting discussion thread:

  1. List the distributions installed, by running following in PowerShell.

    wsl -l
    
  2. Unregister the distribution. Replace the "Ubuntu" below with your distribution name found in Step #1:

    WARNING: THIS COMMAND WILL COMPLETELY UNINSTALL YOUR WSL DISTRO.

      wsl --unregister Ubuntu-22.04
  3. Launch the Ubuntu (or other distribution) which was installed using Microsoft Store  

注2:在window PowerShell启动ubuntu时,因实际文件为windows文件,所以有可能缺少权限

      1)make命令,提示“make: Makefile: Permission denied”,此时执行“chmod 777 Makefile”即可

      2)同样,若链接时提示找不到我们自己编译的库,比如我们自己编译了ffmpeg的静态库,在使用时提示“/usr/bin/ld: cannot find -lavformat: No such file or directory”

         则也有可能是权限造成的(因为在window中文件没有权限的概念),此时使用“chmod” 添加相关权限即可,比如find -name "*.a" | xargs chmod 777

 find -name "*.a" | xargs ls -ls
185656 ---------- 1 ubuntu ubuntu 190110576 Nov  5  2021 ./libavcodec/libavcodec.a
  1472 ---------- 1 ubuntu ubuntu   1504430 Nov  5  2021 ./libavdevice/libavdevice.a
 40360 ---------- 1 ubuntu ubuntu  41325192 Nov  5  2021 ./libavfilter/libavfilter.a
 59516 ---------- 1 ubuntu ubuntu  60941288 Nov  5  2021 ./libavformat/libavformat.a
  5956 -rwxrwxrwx 1 ubuntu ubuntu   6096504 Nov  5  2021 ./libavutil/libavutil.a
   700 ---------- 1 ubuntu ubuntu    716608 Nov  5  2021 ./libswresample/libswresample.a
  7660 ---------- 1 ubuntu ubuntu   7843062 Nov  5  2021 ./libswscale/libswscale.a

 

posted @ 2025-01-14 16:03  cyj2024  阅读(4)  评论(0编辑  收藏  举报