Windows下的仿linux環境msys2介紹


Windows下的仿linux環境msys2介紹


msys2是一種在Windows平臺上模擬Linux運行環境的技術,它的一個優點就在於利用pacman包管理器,我們可以比較輕鬆的使用Linux包管理器的方式來安裝一整套可以在Windows上運行的Linux工具。如果你只是想要在Windows上簡單運行一些Linux程序,那麼msys2是一個很好的選擇。

下載安裝msys2

到清華鏡像源網站來下載msys2,網址如下。

<code>https://mirrors.tuna.tsinghua.edu.cn/msys2/distrib/
/<code>

然後找到適合自己系統架構的安裝包,我這裡是64位,所以選擇下面這個。


Windows下的仿linux環境msys2介紹

下載安裝包


下載完成後安裝即可。第一次打開以後會看到一個比較小的窗口,可以修改一下字體、語言什麼的。如果安裝程序沒有創建快捷方式的話,可以手動去安裝目錄裡面尋找msys2.exe文件。

Windows下的仿linux環境msys2介紹

安裝完成


修改安裝源

前面提到了,msys2可以使用pacman來安裝軟件包,所以第一件事情自然是修改鏡像源的地址了。編輯鏡像源文件的方法很簡單,假設你msys2的安裝路徑是,運行下面的powershell腳本即可。如果你安裝路徑在其他位置,修改腳本即可。

<code>function InsertConentToFileTop {
param(
[String]$filename,
[String]$content
)
$filecontent = Get-Content $filename
$s = @()
$s += $content
$s += $filecontent
$s | Out-File $filename
}

$msys2_install_dir = 'C:\\msys64'
InsertConentToFileTop $msys2_install_dir\\etc\\pacman.d\\mirrorlist.mingw32 'Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686'
InsertConentToFileTop $msys2_install_dir\\etc\\pacman.d\\mirrorlist.mingw64 'Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64'
InsertConentToFileTop $msys2_install_dir\\etc\\pacman.d\\mirrorlist.msys 'Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch'
/<code>

然後在終端中運行pacman -Syu更新系統,就像archlinux那樣。更新完成之後,就可以使用msys2的模擬Linux環境來運行一些bash腳本以及Linux程序了。很多常見的程序都可以在msys2的軟件倉庫中找到,vim、nano、git等程序都可以正常運行。

Windows下的仿linux環境msys2介紹

msys2程序


分享到:


相關文章: