[程式設計] 在 Windows 正常執行 bash

2017-09-02

在 Windows 下安裝 git 的選擇通常是 git for windows ,無論使用安裝版還是免安裝版的 cmder ,都會自帶 bash 這個終端機介面。但經常會遇到找不到指令或 npm 安裝的程式無法正確執行。

一般指令找不到(ls)

  • 在 bash 下輸入 cd ~ 確認你的家目錄在哪(可以 ls 出來看看)。
  • 到家目錄新增一個 .bashrc
  • git for windows/usr/bin 系統絕對路徑合併到 $PATH
    PATH="$PATH:/c/program files/git for windows/usr/bin"
  • 真實路徑或許會因電腦各異,請自行確認。

npm 及相關的指令找不到

  • 找到你的 npm 指令所在位置:where npm
  • 以管理員身分執行系統的 cmd
  • cdgit for windows 路徑
  • 執行:mklink /d node_modules "全域 node_modules 的絕對路徑"