• MSYS2 介绍、下载与安装、Pacman常用命令


    一、MSYS2 介绍

    MSYS2 官网:MSYS2

    MSYS2(Minimal SYStem 2)是一个集成了大量的GNU工具链、工具和库的开源软件包集合。它提供了一个类似于Linux的shell环境,可以在Windows系统中编译和运行许多Linux应用程序和工具。

    MSYS2基于MinGW-w64平台,提供了一个完整的开发环境,包括GCC编译器、GDB调试器、Make、Git版本控制系统和许多其他开发工具。除了常用的开发库和工具之外,MSYS2还提供了许多专门针对Windows平台的库和工具,方便开发人员进行跨平台开发和移植工作。

    由于MSYS2拥有比较完整的Linux工具链和库,因此它成为了许多跨平台开发和移植项目的首选工具。另外,使用MSYS2也可以轻松地在Windows系统中搭建一个类似于Linux的软件开发环境,方便开发人员进行开发和调试工作。

    二、MSYS2、Cygwin、MinGW-w64 区别与联系

    MSYS2是一个包含MinGW-w64工具链、GNU工具集和一些开源库的平台,它提供了一种在Windows上编译和运行Unix/Linux程序的方式。MSYS2与MinGW-w64相似,但比MinGW-w64更完整和稳定,提供了Pacman包管理器以方便用户安装和管理软件包。

    MinGW-w64是一个Windows下的C/C++编程工具集,它提供了运行在Windows上的GNU工具集和GCC编译器。MinGW-w64与MSYS2类似,但主要用于编译Windows本地应用程序,而非Unix/Linux程序。MinGW-w64也可以用于交叉编译,为其他平台生成Windows可执行文件。

    Cygwin是一个在Windows平台上运行的兼容性层,提供了类Unix环境的工具和开发库。Cygwin将Unix程序编译为Windows本地代码,然后在Windows上运行。它提供了最完整的Linux/Unix环境,但相对于MSYS2和MinGW-w64,Cygwin的性能较差。

    因此,MSYS2适用于需要在Windows上编译和运行Unix/Linux程序的场景,MinGW-w64适用于编译Windows本地应用程序的场景,Cygwin适用于需要最完整的Linux/Unix环境的场景。

    三、下载与安装

    1. 安装包下载

    Github 托管地址:Releases · msys2/msys2-installer (github.com)

    官方仓库:Index of /distrib/ (msys2.org)

    安装包有三种:

    • msys2-x86_64-*.exe: GUI安装程序
    • msys2-base-x86_64-*.sfx.exe: 只是自解压归档中的文件(缺少Windows集成,如 快捷方式,卸载入口,但其他工作相同)
    • msys2-base-x86_64-*. tar.xz: 与.sfx.exe相同,但作为xz归档文件

    注意,下载的安装程序可能会被系统识别为不安全的,放心保留即可。

    2. MSYS2安装

    推荐安装GUI的最新版本 (MSYS2 requires 64 bit Windows 8.1 or newer)

    安装过程比较简单,不再详述,重点说下安装路径。

    安装路径要求:要求卷类型为NTFS,路径只有ascii字符,没有重音,没有空格,没有符号链接,没有subst或网络驱动器,不能是FAT

    (short ASCII-only path on a NTFS volume, no accents, no spaces, no symlinks, no subst or network drives, no FAT)

    另外,安装时可能会被 Microsoft Defender SmartScreen 或类似的产品拦截,信任安装即可。

    四、环境/子系统

    MSYS2 安装完成后,你可以看到同时安装了6子程序:

    你可以称它们为MSYS2环境或子系统。

    环境之间的差异主要是环境变量、默认编译器/链接器、体系结构、使用的系统库等。如果您不确定,请使用UCRT64。

    MSYS环境包含基于unix/cygwin的工具,它位于/usr下,它的特殊之处在于它始终处于活动状态。所有其他环境都继承了MSYS环境,并在其基础上添加了各种东西。

    例如,在UCRT64环境中,$PATH变量以/UCRT64/bin:/usr/bin开头,因此在该环境下您可以同时获得所有基于UCRT64的工具以及所有msys工具。

    五、MSYS2 之 Pacman 常用命令

    MSYS2 使用 Pacman 进行软件包管理(包括 安装、更新、卸载等)

    1. pacman -Suy 更新软件包

    该命令会更新核心包和非核心包,核心包指MSYS2本身依赖的包(如:mintty、msys2-runtime、pacman等)

    如果核心包、非核心包都需要更新,则该命令会先更新核心包,然后才能更新非核心包。更新完核心包后,会要求关闭所有已打开的终端,然后再重新执行一遍 pacman -Suy 命令,才会去更新非核心包。

    2. pacman -Qs 搜索已安装的软件包

    3. pacman -Ss 在所有软件包仓库中搜索

    已安装的软件包,会提示 [installed]

    4. pacman -S 安装软件包

    5. pacman -R 卸载软件包

    pacman -R 

    注意,该命令仅卸载软件包,无法卸载该软件包安装时的依赖包,也无法移除该软件运行过程中产生的任何文件。

    6. pacman -Sg 列出软件包

    列出所有软件包组:

    pacman -Sg

    列出某个软件包组中所有的软件包: 

    pacman -Sg 

    7. pacman -Q 列出已安装的软件包

    列出已安装的软件包:

    pacman -Q

    列出所有从 Arch Linux 官方软件仓库安装的软件包:

    pacman -Qe

    8. pacman -Sw 下载软件包但不安装

    pacman -Sw 

    9. pacman -U 从本地安装软件包

    pacman -U 

    支持 tar.xz,tar.zst 两种类型的归档包安装。归档包可以从这里下载:Index of / (msys2.org)

    但需要注意,该本地安装方式,无法自动安装软件包的依赖,需要你自行解决依赖的软件包。

    可以通过 pacman -Qi 查看依赖的软件包。

    10. pacman -Qi 查看软件包详细信息

    pacman -Qi 

    关于pacman命令的更多用法

    可通过 pacman -h 查看

    1. $ pacman -h
    2. usage: pacman [...]
    3. operations:
    4. pacman {-h --help}
    5. pacman {-V --version}
    6. pacman {-D --database}
    7. pacman {-F --files} [options] [file(s)]
    8. pacman {-Q --query} [options] [package(s)]
    9. pacman {-R --remove} [options]
    10. pacman {-S --sync} [options] [package(s)]
    11. pacman {-T --deptest} [options] [package(s)]
    12. pacman {-U --upgrade} [options]
    13. use 'pacman {-h --help}' with an operation for available options

    通过 pacman -h 查看某个参数的更详细用法,如:

    1. $ pacman -S -h
    2. usage: pacman {-S --sync} [options] [package(s)]
    3. options:
    4. -b, --dbpath set an alternate database location
    5. -c, --clean remove old packages from cache directory (-cc for all)
    6. -d, --nodeps skip dependency version checks (-dd to skip all checks)
    7. -g, --groups view all members of a package group
    8. (-gg to view all groups and members)
    9. -i, --info view package information (-ii for extended information)
    10. -l, --list view a list of packages in a repo
    11. -p, --print print the targets instead of performing the operation
    12. -q, --quiet show less information for query and search
    13. -r, --root set an alternate installation root
    14. -s, --search search remote repositories for matching strings
    15. -u, --sysupgrade upgrade installed packages (-uu enables downgrades)
    16. -v, --verbose be verbose
    17. -w, --downloadonly download packages but do not install/upgrade anything
    18. -y, --refresh download fresh package databases from the server
    19. (-yy to force a refresh even if up to date)
    20. --arch <arch> set an alternate architecture
    21. --asdeps install packages as non-explicitly installed
    22. --asexplicit install packages as explicitly installed
    23. --assume-installed
    24. add a virtual package to satisfy dependencies
    25. --cachedir <dir> set an alternate package cache location
    26. --color colorize the output
    27. --config set an alternate configuration file
    28. --confirm always ask for confirmation
    29. --dbonly only modify database entries, not package files
    30. --debug display debug messages
    31. --disable-download-timeout
    32. use relaxed timeouts for download
    33. --gpgdir set an alternate home directory for GnuPG
    34. --hookdir <dir> set an alternate hook location
    35. --ignore ignore a package upgrade (can be used more than once)
    36. --ignoregroup
    37. ignore a group upgrade (can be used more than once)
    38. --logfile set an alternate log file
    39. --needed do not reinstall up to date packages
    40. --noconfirm do not ask for any confirmation
    41. --noprogressbar do not show a progress bar when downloading files
    42. --noscriptlet do not execute the install scriptlet if one exists
    43. --overwrite
    44. overwrite conflicting files (can be used more than once)
    45. --print-format
    46. specify how the targets should be printed
    47. --sysroot operate on a mounted guest system (root-only)

    参考资料:

    What is MSYS2? - MSYS2

    MSYS2 Installer - MSYS2

    Environments - MSYS2

  • 相关阅读:
    第03章 第03章 栈
    MaxCompute(ODPS)中Python UDF使用:如何打包所有依赖包
    学了个学教育游戏与源码
    VUE.js概述——过滤器
    与堆和堆排序相关的问题
    期货十三篇 第三篇 计划篇
    Stable Diffusion WebUI几种解决手崩溃的方法
    10. 同步控制指令
    在excel中做好活动进度矩阵,直接通过代码一键生成工作日报,可以md格式也可以word格式
    调用链路上千条,如何观测 Nacos 的运行状态
  • 原文地址:https://blog.csdn.net/B11050729/article/details/131719012