Windows 终端配置指南:MSYS2 + Fish + 开发环境

1. 安装 Windows 终端

  1. 从 Microsoft Store 安装 Windows Terminal
  2. 或者从 GitHub 发布页下载安装: https://github.com/microsoft/terminal/releases

2. 安装 MSYS2

  1. 下载 MSYS2 安装程序: https://www.msys2.org/
  2. 运行安装程序,建议安装到 C:\msys64
  3. 完成安装后,不要立即运行 MSYS2

3. 设置 MSYS2 为终端默认打开程序

  1. 打开 Windows Terminal
  2. 点击下拉箭头 → 设置
  3. 在 “启动” 选项卡中,设置 “默认配置文件” 为 MSYS2
  4. 如果没有 MSYS2 选项,需要手动添加:(也可以复制一个其他的然后修改内容)
{
    "guid": "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}",
    "hidden": false,
    "name": "MSYS2",
    "commandline": "C:\\msys64\\msys2_shell.cmd -defterm -here -no-start -msys2",
    "startingDirectory": "%USERPROFILE%",
    "icon": "C:\\msys64\\msys2.ico"
}

4. 在 MSYS2 中安装 Fish 并设为默认

  1. 打开 MSYS2 终端
  2. 更新包数据库:
    pacman -Syu
    
  3. 安装 Fish:
    pacman -S fish
    
  4. 设置 Fish 为默认 shell: 修改 .bashrc
       export PATH="/c/msys64/usr/bin:/c/msys64/mingw64/bin:$PATH"
       exec fish
    
  5. 关闭并重新打开终端,现在应该会自动进入 Fish

5. 使用 pacman 安装软件

在 MSYS2 终端中:

# 安装 Git
pacman -S git vim rsync

# 安装其他开发工具 (可选)
pacman -S base-devel vim curl wget unzip

7. 安装 SDKMAN, nvm 和 Miniconda

安装 SDKMAN

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"

# 安装 Java 和 Maven/Gradle
sdk install java 17.0.5-tem
sdk install maven
sdk install gradle

安装 nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

# 重新加载 Fish 配置
source ~/.config/fish/config.fish

# 安装 Node.js
nvm install --lts

安装 Miniconda

  1. 下载 Miniconda 安装脚本:
    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe
    
  2. 运行安装程序:
    ./Miniconda3-latest-Windows-x86_64.exe
    
  3. 按照提示安装,选择"为所有用户安装"或"仅为当前用户安装"
  4. 初始化 conda for Fish:
    conda init fish
    

8. 创建 Python 虚拟环境

conda create -n myenv python=3.9
conda activate myenv

9. 换国内源

MSYS2 换源

编辑 /etc/pacman.d/mirrorlist.mingw32/etc/pacman.d/mirrorlist.mingw64/etc/pacman.d/mirrorlist.msys,添加清华源:

Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686/
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64/
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch/

Conda 换源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

Maven 换源

编辑 ~/.m2/settings.xml:

<mirrors>
    <mirror>
        <id>aliyunmaven</id>
        <mirrorOf>*</mirrorOf>
        <name>阿里云公共仓库</name>
        <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
</mirrors>

10. 配置 IDEA 使用 MSYS2 的 Maven 和 Gradle

  1. 打开 IntelliJ IDEA
  2. 进入 File → Settings → Build, Execution, Deployment → Build Tools → Maven
    • 设置 “Maven home path” 为 C:\msys64\usr\share\maven (或 SDKMAN 安装的路径)
    • 设置 “User settings file” 为 C:\Users\你的用户名\.m2\settings.xml
  3. 进入 File → Settings → Build, Execution, Deployment → Build Tools → Gradle
    • 设置 “Gradle home” 为 C:\msys64\usr\share\gradle (或 SDKMAN 安装的路径)
    • 选择 “Use Gradle from” 选项为 “Gradle home”

注意事项

  1. 所有路径可能需要根据实际安装位置调整
  2. 某些工具可能需要重启终端或 IDEA 才能生效
  3. 如果遇到权限问题,可能需要以管理员身份运行某些命令
  4. Fish 的配置文件位于 ~/.config/fish/config.fish
Logo

一站式 AI 云服务平台

更多推荐