2025年12月13日 星期六

在 Windows 上安裝原生版 Claude Code

最近與明賢表弟在 LINE 上聊到 Vibe coding, 他今年用 Claude Code 開發軟體的經驗是, 以後程式員都得放棄自行 coding 的想法, 因為 AI 寫程式的能力太強, 軟體工程師都應轉型為具有系統思維的 PM. 這讓我對 Claude Code 突然有了興趣, 在 momo 買了市面上僅有的兩本書來一探究竟 : 


今天先把 Claude Code 開發環境架起來, 主要參考旗標這本書, 在 LG Gram 筆電上透過 Scoop 軟體從網路下載 PowerShell 腳本程式安裝原生版 Cloude Code, 步驟如下 : 


1. 設定 PowerShell 視窗腳本執行原則 (Execution Policy) : 

首先在 Windows 搜尋 powershell 並直接開啟此視窗程式 (不要用系統管理員), 然後複製貼上下列指令按 Enter 執行, 這樣才能執行從網路下載具有數位簽章的 PowerShell 腳本程式 Scoop :

PS C:\Users\tony1> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser  
PS C:\Users\tony1>




書上說會出現 Yes/No 詢問提示, 但我的沒有, 這可能是 -Scope CurrentUser 的關係, 這表示變更範圍只影響目前使用者, 不會影響到系統上的其他使用者或整個電腦, 所以 PowerShell 有時會省略提示, 直接接受對當前使用者設定的修改. 


2. 安裝套件管理工具 Scoop : 

貼上下列指令從網路下載 Scoop 腳本執行安裝 :

PS C:\Users\tony1> Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression   
Initializing...
Downloading...
Extracting...
Creating shim...
Adding ~\scoop\shims to your path.
Scoop was installed successfully!
Type 'scoop help' for instructions.


3. 安裝 Git 與設定 git-bash 環境變數 : 

使用 Scoop 來安裝 Git : 

PS C:\Users\tony1> scoop install git   
Scoop uses Git to update itself. Run 'scoop install git' and try again.
Installing '7zip' (25.01) [64bit] from 'main' bucket
7z2501-x64.msi (1.9 MB) [====================================================] 100%
Checking hash of 7z2501-x64.msi ... ok.
Extracting 7z2501-x64.msi ... done.
Linking ~\scoop\apps\7zip\current => ~\scoop\apps\7zip\25.01
Creating shim for '7z'.
Creating shim for '7zFM'.
Making C:\Users\tony1\scoop\shims\7zfm.exe a GUI binary.
Creating shim for '7zG'.
Making C:\Users\tony1\scoop\shims\7zg.exe a GUI binary.
Creating shortcut for 7-Zip (7zFM.exe)
Persisting Codecs
Persisting Formats
Running post_install script...done.
'7zip' (25.01) was installed successfully!
Notes
-----
Add 7-Zip as a context menu option by running:
reg import "C:\Users\tony1\scoop\apps\7zip\current\install-context.reg"
Installing 'git' (2.52.0) [64bit] from 'main' bucket
PortableGit-2.52.0-64-bit.7z.exe (57.4 MB) [=================================] 100%
Checking hash of PortableGit-2.52.0-64-bit.7z.exe ... ok.
Extracting PortableGit-2.52.0-64-bit.7z.exe ... done.
Linking ~\scoop\apps\git\current => ~\scoop\apps\git\2.52.0
Creating shim for 'sh'.
Creating shim for 'bash'.
Creating shim for 'git'.
Creating shim for 'gitk'.
Making C:\Users\tony1\scoop\shims\gitk.exe a GUI binary.
Creating shim for 'git-gui'.
Making C:\Users\tony1\scoop\shims\git-gui.exe a GUI binary.
Creating shim for 'scalar'.
Creating shim for 'tig'.
Creating shim for 'git-bash'.
Making C:\Users\tony1\scoop\shims\git-bash.exe a GUI binary.
Creating shortcut for Git Bash (git-bash.exe)
Creating shortcut for Git GUI (git-gui.exe)
Running post_install script...done.
'git' (2.52.0) was installed successfully!
Notes
-----
Set Git Credential Manager Core by running: "git config --global credential.helper
manager"

To add context menu entries, run
'C:\Users\tony1\scoop\apps\git\current\install-context.reg'

To create file-associations for .git* and .sh files, run
'C:\Users\tony1\scoop\apps\git\current\install-file-associations.reg'

注意, 此處安裝 Git 並非是要用到版本控制, 而是要利用 Git 所附的 git-bash 來執行 Claude Code. 用 where.exe 查詢 bash 程式位置 (若有多個要找路徑中含有 scoop 者) : 

PS C:\Users\tony1> where.exe bash
C:\Users\tony1\scoop\shims\bash.exe
PS C:\Users\tony1>

先將 git-bash 路徑複製下來, 按搜尋鈕輸入 "環境變數" :




新增使用者變數 CLAUDE_CODE_GIT_BASH_PATH :




貼上前面複製的 git-bash 路徑 : 




按確定完成設定 :




關閉 Power Shell 視窗重開, 這樣新增的環境變數才會生效. 以上設定是因為 Claude Code 固定會到環境變數 CLAUDE_CODE_GIT_BASH_PATH 去找 git-bash 路徑之故. 


4. 安裝原生版 Claude Code : 

在重新開啟的 Power Shell 視窗輸入下列指令安裝 Claude Code  :

PS C:\Users\tony1> irm https://claude.ai/install.ps1 | iex   
Setting up Claude Code...

√ Claude Code successfully installed!

  Version: 2.0.65

  Location: C:\Users\tony1\.local\bin\claude.exe


  Next: Run claude --help to get started

‼ Setup notes:
  • Native installation exists but C:\Users\tony1\.local\bin is not in your PATH. Add it by opening: System Properties →
   Environment Variables → Edit User PATH → New → Add the path above. Then restart your terminal.


✅ Installation complete!


這樣便安裝好 Claude Code 了, 在 Setup notes 中提醒要將 Claude Code 的執行檔路徑加入使用者環境變數 Path 中, 這樣以後才能在任何路徑下執行 Claude Code, 設定方式與上面設定環境變數 CLAUDE_CODE_GIT_BASH_PATH 相同, 點選使用者變數 Path 按編輯鈕 :




按新增鈕 : 




貼上 Claude Code 程式路徑 C:\Users\tony1\.local\bin 後按確定即可 :




以上便完成 Claude Code 安裝與設定了.

關閉 Power Shell 視窗重開, 下 claude 指令即可啟動 Claude Code : 

PS C:\Users\tony1> claude 




按上下鍵選擇一個終端機樣式, 直接按 Enter 使用預設 Dark mode 即可. 接下來會進入登入頁面並要求選擇一個付費方案 (Pro/Max), 這部分先 hold 一下, 後續要使用時再來設定. 接下來先用 scoop 安裝其他會用到的軟體. 

沒有留言:

張貼留言