前言
在上一篇文章 [Windows] Windows Terminal Preview 初體驗 介紹了 Windows Terminal 的基本操作與使用,其中提到在安裝完預設提供 command 為 powershell 和 cmd 命令提示字元兩種,其實在 Windows Terminal 支援多種 command line,這一篇文章就來介紹如何在 Windows Terminal Preview 新增 Bash command line 的方法。
啟用 Linux Bash Shell
如果要在 Windows Terminal 使用 Bash.exe 需要先啟用 Window OS 的 Linux Bash Shell 功能,公司筆電是使用最新版 Windows 10,因此以下就簡單介紹在 Windows 10 中如何啟用 Linux Bash
安裝 Windows Subsystem for Linux
首先使用管理者 admin 權限開啟 powershell
接著在 powershell 輸入下列指令
安裝 Ubuntu
下一步到 Windows 商店下載 Linux 子系統,在 Microsoft Store 提供多個 Linux 子系統像是 Ubuntu、OpenSUSE、SLES 可以下載,可以在 Store 輸入 Linux 就可以輕易地找到 Ubuntu,下載完畢後可以點選啟用
第一次啟用 ubuntu 會需要一點時間進行初始化設定與安裝,完畢之後會要求你輸入帳號密碼的動作
透過以上步驟,順利的完成啟用 Windows Subsystem for Linux 與 安裝 Ubuntu 的動作
新增 Command Line
在 Windows Terminal 中的設定可以透過 ⬇ 中的 settings 來進行設定,按下後會請使用者選擇想要開啟設定檔的編輯器工具
在 Windows Terminal 設定檔名為 Profiles.json,要調整可以到下列路徑進行調整
在重新開啟 Windows Terminal,在點擊右上方的 + 後就可以透過看到新增的 commandline
透過以上簡單的幾個步驟就完成在 在 Windows Terminal 新增 Linux Bash,希望有幫助到有需要的朋友 :)
How to Install Linux Bash Shell on Windows 10
在上一篇文章 [Windows] Windows Terminal Preview 初體驗 介紹了 Windows Terminal 的基本操作與使用,其中提到在安裝完預設提供 command 為 powershell 和 cmd 命令提示字元兩種,其實在 Windows Terminal 支援多種 command line,這一篇文章就來介紹如何在 Windows Terminal Preview 新增 Bash command line 的方法。
啟用 Linux Bash Shell
如果要在 Windows Terminal 使用 Bash.exe 需要先啟用 Window OS 的 Linux Bash Shell 功能,公司筆電是使用最新版 Windows 10,因此以下就簡單介紹在 Windows 10 中如何啟用 Linux Bash
安裝 Windows Subsystem for Linux
接著在 powershell 輸入下列指令
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux安裝完畢之後會詢問是否要重新啟動電腦,選擇 y 就會進行立即重啟的動作
安裝 Ubuntu
下一步到 Windows 商店下載 Linux 子系統,在 Microsoft Store 提供多個 Linux 子系統像是 Ubuntu、OpenSUSE、SLES 可以下載,可以在 Store 輸入 Linux 就可以輕易地找到 Ubuntu,下載完畢後可以點選啟用
第一次啟用 ubuntu 會需要一點時間進行初始化設定與安裝,完畢之後會要求你輸入帳號密碼的動作
透過以上步驟,順利的完成啟用 Windows Subsystem for Linux 與 安裝 Ubuntu 的動作
新增 Command Line
在 Windows Terminal 中的設定可以透過 ⬇ 中的 settings 來進行設定,按下後會請使用者選擇想要開啟設定檔的編輯器工具
在 Windows Terminal 設定檔名為 Profiles.json,要調整可以到下列路徑進行調整
userName\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState找到設定檔後可以透過文字編輯器進行編輯,用 Visual Studo Code 開啟後可以看到 profiles 區塊,在 Windows Terminal 安裝完成之後 profiles 一共有兩個區塊,內容分別定義 powershell 與 cmd 兩種設定,以 powershell 為例配置設定如下
{
"acrylicOpacity" : 0.5,
"background" : "#012456",
"backgroundImage" : "D:/Marcus/iron_man.jpg",
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "powershell.exe",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Fira Code",
"fontSize" : 14,
"guid" : "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
"name" : "Windows PowerShell",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : false
}
重要的項目為 name、guid、commandline 等設定,說明如下- guid : 每組 commandline 定義屬於自己專用且不能重複的 guid
- name : 顯示在 Windows Terminal + 中顯示的名字
- commandline : 執行的 commandline
{
"acrylicOpacity" : 0.75,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "bash.exe",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Consolas",
"fontSize" : 10,
"guid" : "{9acb9455-ca41-5af7-950f-6bca1bc9722f}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.scale-100.png",
"name" : "Linux Bash Shell",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : true
}
新增 Python{
"acrylicOpacity" : 0.75,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "py.exe",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Consolas",
"fontSize" : 10,
"guid" : "{1850e97f-16dc-4281-9ea9-0100c4e852c5}",
"historySize" : 9001,
"icon" : "C:/Users/marcus/AppData/Local/Programs/Python/Python37/Lib/test/imghdrdata/python.png",
"name" : "Python",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : true
}
最後要小小提醒的是在編輯 Profiles.json 檔時需多加留意格式,如果對於 json 格式不熟悉可以到現在 json 格式檢查網站進行確認後再貼上,如果格式錯誤會造成讀取異常,可以看到下列畫面在重新開啟 Windows Terminal,在點擊右上方的 + 後就可以透過看到新增的 commandline
透過以上簡單的幾個步驟就完成在 在 Windows Terminal 新增 Linux Bash,希望有幫助到有需要的朋友 :)
參考
終於來了!實測 Windows 10 更新後,安裝使用Bash on Ubuntu on WindowsHow to Install Linux Bash Shell on Windows 10



















