msys2常用配置
Windows
安装msys2
MSYS2
是 Cygwin
的分支。喜欢完整体验、不在乎磁盘占用等等,还是推荐 Cygwin
。
https://blog.youkuaiyun.com/ayang1986/article/details/79377827
# Windows使用choco包管理器安装msys2
choco install msys2 -y
把msys2
集成到Windows Terminal
中
参考: https://blog.youkuaiyun.com/chenxizhan1995/article/details/109609823
将下方的json
配置添加到profile.defaults.list
中
{
// MSYS2
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6301}",
"name": "MSYS2",
// "commandline": "C:\\tools\\msys64\\msys2_shell.cmd -msys -defterm -no-start",
"commandline": "C:\\msys64\\msys2_shell.cmd -msys -defterm -no-start",
"hidden": false,
"fontSize": 12,
"tabTitle": "MSYS2",
// "colorScheme":"Campbell Powershell",
"colorScheme": "Campbell",
"startingDirectory": "%userprofile%",
"suppressApplicationTitle": true
}
为pwsh设置一个msys2快接打开命令
打开的msys2命令行是嵌套在pwsh中的
# 编辑$profile
notepad $profile
$profile
内容如下:
function msys2 {
& "C:\tools\msys64\usr\bin\bash.exe" --login -i
}
接下来在pwsh中执行msys2就可以切换到msys2了。
pacman
常用命令
参考: https://blog.youkuaiyun.com/mozart_cai/article/details/92385567
# 升级系统及所有已经安装的软件
pacman -Syu
# 强制同步软件包数据库并升级
pacman -Syyu
# 安装软件。也可以同时安装多个包,只需以空格分隔包名即可
pacman -S 软件名
显示软件包详情
# 查看某个软件包信息,显示软件简介,构架,依赖,大小等详细信息
pacman -Qi 软件名
# 查看某软件包组所包含的所有软件包
pacman -Sg 软件包组
# 列出软件仓库上所有的软件包组
pacman -Sg
搜索软件包
# 在仓库中搜索含关键字的软件包,并用简洁方式显示
pacman -Ssq 关键字
# 搜索软件包
pacman -Ss git
# 获取软件包信息
pacman -Si git
# 搜索已安装的软件包
pacman -Qs 关键字
卸载软件包
# 删除软件,同时删除本机上只有该软件依赖的软件
pacman -Rs 软件名
# 删除软件,同时删除不再被任何软件所需要的依赖
pacman -Ru 软件名
#清理未安装的包文件,包文件位于 /var/cache/pacman/pkg/ 目录
pacman -Sc
#清理所有的缓存文件
pacman -Scc
查询文件由哪个包提供
https://wiki.archlinux.org/title/Pacman_(简体中文)/Rosetta_(简体中文)
# 查出文件由哪一个包提供
pacman -Fy 要查询的命令
配置proxy
参考: https://blog.youkuaiyun.com/omaidb/article/details/116019501
https://www.cnblogs.com/marklove/p/10760637.html
步骤和Linux
配置proxy
完全一致;
编辑msys64
下用户的.bashrc
;
配置http代理
export http_proxy="http://proxy.ibm.com:912"
export https_proxy="http://proxy.ibm.com:912"
export all_proxy="http://proxy.ibm.com:912"
# 配置带认证的http
export all_proxy=http://user:pass@192.158.8.8:8080
配置socks5代理
新版的msys2
已经支持socks
.
# 配置socks5 代理
export http_proxy=socks5://10.0.0.52:1080
export https_proxy=socks5://10.0.0.52:1080
export all_proxy=socks5://10.0.0.52:1080
# 配置带认证的socks5
export all_proxy=socks5://user:pass@192.158.8.8:8080
使配置生效
然后source
一下.bashrc
即可.
# 使配置生效
source ~/.bashrc
msys2
修改国内源
参考: https://mirrors.tuna.tsinghua.edu.cn/help/msys2/
源
文件包括:
C:\tools\msys64\etc\pacman.d\mirrorlist.mingw
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw
C:\tools\msys64\etc\pacman.d\mirrorlist.mingw32
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686
C:\tools\msys64\etc\pacman.d\mirrorlist.mingw64
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64
C:\tools\msys64\etc\pacman.d\mirrorlist.ucrt64
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/ucrt64
C:\tools\msys64\etc\pacman.d\mirrorlist.clang32
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/clang32
C:\tools\msys64\etc\pacman.d\mirrorlist.clang64
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/clang64
C:\tools\msys64\etc\pacman.d\mirrorlist.msys
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch
修改完源之后,执行pacman -Sy
刷新源.
配置pacman
创建一个新的 GnuPG 密钥环
,
位于 /etc/pacman.d/gnupg
目录下
# 清除已有的密钥,创建一个新的 GnuPG 密钥环
pacman-key --init
导入 MSYS2 官方密钥
# 导入 MSYS2 官方密钥
pacman-key --populate msys2
# 接受软件包维护者的公钥
pacman-key --refresh-keys
# 导入软件包维护者的公钥
pacman-key --recv-keys <KEY-ID>
pacman-key --lsign-key <KEY-ID>
在上述命令中将 替换为错误信息中提供的钥匙编号。
更新系统
# 强制同步软件包数据库并升级
pacman -Syyu
更新pacman数据库—必须执行
# 更新 pacman 数据库
pacman -S --dbonly pacman
常见问题
msys2
访问其他盘
# 访问E盘
cd /e/
# 访问E盘子目录
cd /c/opt
## 如果子目录有空格,必须用双引号引起来
cd "/c/Program Files"
msys2
安装tmux
不间断会话—已不可用
参考: https://blog.youkuaiyun.com/omaidb/article/details/120385011
Windows
下像Linux
一样使用tmux关闭终端
而不影响
命令行运行.
# 安装tmux
pacman -S tmux
msys2下运行tumux会报错: Windows - tmux: open terminal failed: not a terminal
WIndows拷贝过来的密钥对无法使用
# 安装dos2unix
pacman -S dos2unix
## 将.ssh目录下的密钥对转为unix格式
cd ~/.ssh
# -o:写入到源文件
dos2unix -o *
msys2安装scp实现大文件断点续传-依赖包
# 需要用ssh和rsync来完成大文件上传
pacman -S wget openssh rsync
scp
大文件断电续传操作参考: https://blog.youkuaiyun.com/omaidb/article/details/121746997
msys2安装常用包
# 安装软件包
pacman -S openbsd-netcat ca-certificates
# 安装tmux
pacman -S tmux
# 安装socat
pacman -S socat
# 安装telnet
pacman -S inetutils
# 安装curl和wget
pacman -S curl wget
# 安装dos2unix
pacman -S dos2unix
# 安装ssh客户端
pacman -S openssh
# 安装git
pacman -S git
# 安装tree ,以树的格式查看文件夹
pacman -S tree
# 安装vim编辑器
pacman -S vim
# 安装终端自动补全
pacman -S bash-completion
# 安装top命令
## --noconfirm 不询问
pacman -S procps-ng --noconfirm
# 安装ncdu
pacman -S ncdu
msys2安装常用编译环境
# 安装依赖包
pacman -S gcc mingw-w64-x86_64-gcc mingw-w64-x86_64-db
pacman -S cmake make openssl
pacman -S zlib ncurses
msys2使用dig命令
pacman源中找不到dig命令。
# Windows安装dig
choco install bind-toolsonly -y
# 查看dig.exe的路径
which dig
在msys2
中的.bashrc
中配置alias dig
或者在mysy2
中创建/etc/profile.d/aliases.sh
全局别名
配置文件
# 创建系统级别名配置文件
touch /etc/profile.d/aliases.sh
# 在.bashrc中设置alias dig
alias dig="/c/ProgramData/chocolatey/bin/dig.exe"
在msys2
中测试dig命令
msys2使用vscode
在msys2
中,编辑.bashrc
为code
添加别名
alias code="/d/Program\ Files/Microsoft\ VS\ Code/bin/code.cmd"