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

您所在的位置:网站首页 常用cad指令大全下载安装教程 MSYS2 介绍、下载与安装、Pacman常用命令

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

2024-05-25 07:35| 来源: 网络整理| 查看: 265

一、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 查看

$ pacman -h usage: pacman [...] operations: pacman {-h --help} pacman {-V --version} pacman {-D --database} pacman {-F --files} [options] [file(s)] pacman {-Q --query} [options] [package(s)] pacman {-R --remove} [options] pacman {-S --sync} [options] [package(s)] pacman {-T --deptest} [options] [package(s)] pacman {-U --upgrade} [options] use 'pacman {-h --help}' with an operation for available options

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

$ pacman -S -h usage: pacman {-S --sync} [options] [package(s)] options: -b, --dbpath set an alternate database location -c, --clean remove old packages from cache directory (-cc for all) -d, --nodeps skip dependency version checks (-dd to skip all checks) -g, --groups view all members of a package group (-gg to view all groups and members) -i, --info view package information (-ii for extended information) -l, --list view a list of packages in a repo -p, --print print the targets instead of performing the operation -q, --quiet show less information for query and search -r, --root set an alternate installation root -s, --search search remote repositories for matching strings -u, --sysupgrade upgrade installed packages (-uu enables downgrades) -v, --verbose be verbose -w, --downloadonly download packages but do not install/upgrade anything -y, --refresh download fresh package databases from the server (-yy to force a refresh even if up to date) --arch set an alternate architecture --asdeps install packages as non-explicitly installed --asexplicit install packages as explicitly installed --assume-installed add a virtual package to satisfy dependencies --cachedir set an alternate package cache location --color colorize the output --config set an alternate configuration file --confirm always ask for confirmation --dbonly only modify database entries, not package files --debug display debug messages --disable-download-timeout use relaxed timeouts for download --gpgdir set an alternate home directory for GnuPG --hookdir set an alternate hook location --ignore ignore a package upgrade (can be used more than once) --ignoregroup ignore a group upgrade (can be used more than once) --logfile set an alternate log file --needed do not reinstall up to date packages --noconfirm do not ask for any confirmation --noprogressbar do not show a progress bar when downloading files --noscriptlet do not execute the install scriptlet if one exists --overwrite overwrite conflicting files (can be used more than once) --print-format specify how the targets should be printed --sysroot operate on a mounted guest system (root-only)

参考资料:

What is MSYS2? - MSYS2

MSYS2 Installer - MSYS2

Environments - MSYS2



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3