使用 PowerShell 安装 Linux

发布时间:2022-06-20 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了使用 PowerShell 安装 Linux脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

 

因需要使用 linux 下的 make 编译 lib 库,推出该章节。

 

当然也可以在 windows 下使用 make 编译,需要安装 mingw,以及使用 mingw-make.exe 来配置环境变量,然后可以使用 make 命令。

 

此处使用 Powershell 命令来安装 linux ,并使用 linux 来编译 lib 库。

 

先使用 Powershell 启动 Linux:Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

 

PS C:Windowssystem32> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux                                                                                                                                    
Path          :
Online        : True
RestartNeeded : False



PS C:Windowssystem32> cd C:data
PS C:data> Invoke-WebRequest -Uri https://wsldownload.azureedge.net/Ubuntu_1604.2019.523.0_x64.appx -OutFile Ubuntu.appx -UseBasicParsing
PS C:data> dir


    Directory: C:data


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         2/16/2022   4:11 PM      208755084 Ubuntu.appx


PS C:data> Add-AppxPackage .Ubuntu.appx
Add-AppxPackage : Cannot find path 'C:data.Ubuntu.appx' because it does not exist.
At line:1 char:1
+ Add-AppxPackage .Ubuntu.appx
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:data.Ubuntu.appx:String) [Add-AppxPackage], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

PS C:data> Add-AppxPackage .Ubuntu.appx
PS C:data>

 

 

然后在 Windows Start 中搜索 Ubuntu 并启动:

 

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: admin
Enter new UNIX password:
Retype new UNIX password:
Sorry, passwords do not match
passwd: Authentication token manipulation error
passwd: password unchanged
Try again? [y/N] y
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

admin@YK-SZPC00093:~$

 

 

然后可以使用 Linux 命令了

 

admin@YK-SZPC00093:~$ cmake -v
The program 'cmake' is currently not installed. You can install it by typing:
sudo apt install cmake
admin@YK-SZPC00093:~$ sudo apt install cmake
[sudo] password for jessea:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
  libfreetype6
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
  binutils cmake-data cpp cpp-5 gcc gcc-5 libarchive13 libasan2 libatomic1 libc-dev-bin libc6-dev libcc1-0 libcilkrts5
  libcurl3 libgcc-5-dev libgomp1 libisl15 libitm1 libjsoncpp1 liblsan0 libmpc3 libmpx0 libquadmath0 libtsan0 libubsan0
  linux-libc-dev make manpages-dev
Suggested packages:
  binutils-doc codeblocks eclipse ninja-build cpp-doc gcc-5-locales gcc-multilib autoconf automake libtool flex bison
  gdb gcc-doc gcc-5-multilib gcc-5-doc libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan2-dbg liblsan0-dbg
  libtsan0-dbg libubsan0-dbg libcilkrts5-dbg libmpx0-dbg libquadmath0-dbg lrzip glibc-doc make-doc
The following NEW packages will be installed:
  binutils cmake cmake-data cpp cpp-5 gcc gcc-5 libarchive13 libasan2 libatomic1 libc-dev-bin libc6-dev libcc1-0
  libcilkrts5 libcurl3 libgcc-5-dev libgomp1 libisl15 libitm1 libjsoncpp1 liblsan0 libmpc3 libmpx0 libquadmath0
  libtsan0 libubsan0 linux-libc-dev make manpages-dev
0 upgraded, 29 newly installed, 0 to remove and 0 not upgraded.
Need to get 31.7 MB of archives.
After this operation, 122 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 cmake-data all 3.5.1-1ubuntu3 [1,121 kB]
Err:2 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libarchive13 amd64 3.1.2-11ubuntu0.16.04.6
  404  Not Found [IP: 91.189.88.152 80]
Ign:3 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libcurl3 amd64 7.47.0-1ubuntu2.12
Get:4 http://archive.ubuntu.com/ubuntu xenial/main amd64 libjsoncpp1 amd64 1.7.2-1 [73.0 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 cmake amd64 3.5.1-1ubuntu3 [2,623 kB]
Err:2 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libarchive13 amd64 3.1.2-11ubuntu0.16.04.6
  404  Not Found [IP: 91.189.88.152 80]
Err:3 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libcurl3 amd64 7.47.0-1ubuntu2.12
  404  Not Found [IP: 91.189.88.152 80]
7% [5 cmake 883 kB/2,623 kB 34%]

 

 

这个版本的 linux 还是缺少很多库的,不是一个完整版本,可以看到 gcc 都没有安装:

Need to get 31.7 MB of archives.
After this operation, 122 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 cmake-data all 3.5.1-1ubuntu3 [1,121 kB]
Err:2 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libarchive13 amd64 3.1.2-11ubuntu0.16.04.6
  404  Not Found [IP: 91.189.88.152 80]
Ign:3 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libcurl3 amd64 7.47.0-1ubuntu2.12
Get:4 http://archive.ubuntu.com/ubuntu xenial/main amd64 libjsoncpp1 amd64 1.7.2-1 [73.0 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 cmake amd64 3.5.1-1ubuntu3 [2,623 kB]
Err:2 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libarchive13 amd64 3.1.2-11ubuntu0.16.04.6
  404  Not Found [IP: 91.189.88.152 80]
Err:3 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libcurl3 amd64 7.47.0-1ubuntu2.12
  404  Not Found [IP: 91.189.88.152 80]
Get:6 http://archive.ubuntu.com/ubuntu xenial/main amd64 libmpc3 amd64 1.0.3-1 [39.7 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 binutils amd64 2.26.1-1ubuntu1~16.04.8 [2,312 kB]
Get:8 http://archive.ubuntu.com/ubuntu xenial/main amd64 libisl15 amd64 0.16.1-1 [524 kB]
Err:9 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 cpp-5 amd64 5.4.0-6ubuntu1~16.04.11
  404  Not Found [IP: 91.189.88.152 80]
Get:10 http://archive.ubuntu.com/ubuntu xenial/main amd64 cpp amd64 4:5.3.1-1ubuntu1 [27.7 kB]
Err:11 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libcc1-0 amd64 5.4.0-6ubuntu1~16.04.11
  404  Not Found [IP: 91.189.88.152 80]
Err:12 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libgomp1 amd64 5.4.0-6ubuntu1~16.04.11
  404  Not Found [IP: 91.189.88.152 80]
Err:13 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libitm1 amd64 5.4.0-6ubuntu1~16.04.11
  404  Not Found [IP: 91.189.88.152 80]
Err:14 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libatomic1 amd64 5.4.0-6ubuntu1~16.04.11
  404  Not Found [IP: 91.189.88.152 80]
Err:15 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libasan2 amd64 5.4.0-6ubuntu1~16.04.11
  404  Not Found [IP: 91.189.88.152 80]
Err:16 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 liblsan0 amd64 5.4.0-6ubuntu1~16.04.11
  404  Not Found [IP: 91.189.88.152 80]
Err:17 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libtsan0 amd64 5.4.0-6ubuntu1~16.04.11
  404  Not Found [IP: 91.189.88.152 80]
Err:18 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libubsan0 amd64 5.4.0-6ubuntu1~16.04.11
  404  Not Found [IP: 91.189.88.152 80]
Err:19 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libcilkrts5 amd64 5.4.0-6ubuntu1~16.04.11
  404  Not Found [IP: 91.189.88.152 80]
Err:20 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libmpx0 amd64 5.4.0-6ubuntu1~16.04.11
  404  Not Found [IP: 91.189.88.152 80]
Err:21 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libquadmath0 amd64 5.4.0-6ubuntu1~16.04.11
  404  Not Found [IP: 91.189.88.152 80]
Err:22 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libgcc-5-dev amd64 5.4.0-6ubuntu1~16.04.11
  404  Not Found [IP: 91.189.88.152 80]
Err:23 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 gcc-5 amd64 5.4.0-6ubuntu1~16.04.11
  404  Not Found [IP: 91.189.88.152 80]
Get:24 http://archive.ubuntu.com/ubuntu xenial/main amd64 gcc amd64 4:5.3.1-1ubuntu1 [5,244 B]
Err:25 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libc-dev-bin amd64 2.23-0ubuntu11
  404  Not Found [IP: 91.189.88.152 80]
Err:26 http://security.ubuntu.com/ubuntu xenial-security/main amd64 linux-libc-dev amd64 4.4.0-148.174
  404  Not Found [IP: 91.189.88.152 80]
Err:27 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libc6-dev amd64 2.23-0ubuntu11
  404  Not Found [IP: 91.189.88.152 80]
Get:28 http://archive.ubuntu.com/ubuntu xenial/main amd64 make amd64 4.1-6 [151 kB]
Err:26 http://security.ubuntu.com/ubuntu xenial-security/main amd64 linux-libc-dev amd64 4.4.0-148.174
  404  Not Found [IP: 91.189.88.152 80]
Get:29 http://archive.ubuntu.com/ubuntu xenial/main amd64 manpages-dev all 4.04-2 [2,048 kB]
Fetched 8,924 kB in 35s (252 kB/s)
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/liba/libarchive/libarchive13_3.1.2-11ubuntu0.16.04.6_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/c/curl/libcurl3_7.47.0-1ubuntu2.12_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/cpp-5_5.4.0-6ubuntu1~16.04.11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/libcc1-0_5.4.0-6ubuntu1~16.04.11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/libgomp1_5.4.0-6ubuntu1~16.04.11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/libitm1_5.4.0-6ubuntu1~16.04.11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/libatomic1_5.4.0-6ubuntu1~16.04.11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/libasan2_5.4.0-6ubuntu1~16.04.11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/liblsan0_5.4.0-6ubuntu1~16.04.11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/libtsan0_5.4.0-6ubuntu1~16.04.11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/libubsan0_5.4.0-6ubuntu1~16.04.11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/libcilkrts5_5.4.0-6ubuntu1~16.04.11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/libmpx0_5.4.0-6ubuntu1~16.04.11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/libquadmath0_5.4.0-6ubuntu1~16.04.11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/libgcc-5-dev_5.4.0-6ubuntu1~16.04.11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/gcc-5_5.4.0-6ubuntu1~16.04.11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/glibc/libc-dev-bin_2.23-0ubuntu11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/l/linux/linux-libc-dev_4.4.0-148.174_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/g/glibc/libc6-dev_2.23-0ubuntu11_amd64.deb  404  Not Found [IP: 91.189.88.152 80]

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
admin@YK-SZPC00093:~$ gcc -v
The program 'gcc' is currently not installed. You can install it by typing:
sudo apt install gcc
admin@YK-SZPC00093:~$ sudo apt install gcc

 

后续只需要使用命令安装好所需的软件和环境就好。

 

 

Powershell 卸载 Linux :

 

//获取 linux name
>Get-AppxPackage *ubuntu*
//从结果中拿到 Name:CanonicalGroupLimited.Ubuntu16.04onWindows,然后执行以下
>Get-AppxPackage CanonicalGroupLimited.Ubuntu16.04onWindows | Remove-AppxPackage

 

Powershell 禁用 Linux:

>Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

 

 

脚本宝典总结

以上是脚本宝典为你收集整理的使用 PowerShell 安装 Linux全部内容,希望文章能够帮你解决使用 PowerShell 安装 Linux所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: